//CDK : 2022-02-04
set more off
cd "D:/JOP replication files/"
log using "Kam et al. Replication file.log", replace
use "deidentified_2016.dta", clear 

*****
*TIME VARIABLES
*****
*Monthly variables
*generate variable for election day
*generate elapsed days between birth and election day
gen dategen2016 = date("11/08/16","MDY",2016)
gen dob_B_year = substr(dob_B, 1, 4)
gen dob_B_month = substr(dob_B, 5, 2)
gen dob_B_day = substr(dob_B, 7, 2)
egen dob_B_newformat = concat(dob_B_month dob_B_day dob_B_year)
gen baby_dob_DATE=date(dob_B_newformat, "MDY")
gen elapseddays = baby_dob_DATE-dategen2016

gen electionday=0
replace electionday=1 if elapseddays==0

*Weekly variables
recode elapseddays (-364/-358 =-52) (-357/-351 =-51) (-350/-344 =-50) (-343/-337 =-49) (-336/-330 =-48) (-329/-323 =-47) (-322/-316 =-46) (-315/-309 =-45) (-308/-302 =-44) (-301/-295 =-43) (-294/-288 =-42) (-287/-281 =-41) (-280/-274 =-40) (-273/-267 =-39) (-266/-260 =-38) (-259/-253 =-37) (-252/-246 =-36) (-245/-239 =-35) (-238/-232 =-34) (-231/-225 =-33) (-224/-218 =-32) (-217/-211 =-31) (-210/-204 =-30) (-203/-197 =-29) (-196/-190 =-28) (-189/-183 =-27) (-182/-176 =-26) (-175/-169 =-25) (-168/-162 =-24) (-161/-155 =-23) (-154/-148 =-22) (-147/-141 =-21) (-140/-134 =-20) (-133/-127 =-19) (-126/-120 =-18) (-119/-113 =-17) (-112/-106 =-16) (-105/-99 =-15) (-98/-92 =-14) (-91/-85 =-13) (-84/-78 =-12) (-77/-71 =-11) (-70/-64 =-10) (-63/-57 =-9) (-56/-50 =-8) (-49/-43 =-7) (-42/-36 =-6) (-35/-29 =-5) (-28/-22 =-4) (-21/-15 =-3) (-14/-8 =-2) (-7/-1 =-1) (0=0) (1/7 =1) (8/14 =2) (15/21 =3) (22/28 =4) (29/35 =5) (36/42 =6) (43/49 =7) (50/56 =8) (57/63 =9) (64/70 =10) (71/77 =11) (78/84 =12) (85/91 =13) (92/98 =14) (99/105 =15) (106/112 =16) (113/119 =17) (120/126 =18) (127/133 =19) (134/140 =20) (141/147 =21) (148/154 =22) (155/161 =23) (162/168 =24) (169/175 =25) (176/182 =26) (183/189 =27) (190/196 =28) (197/203 =29) (204/210 =30) (211/217 =31) (218/224 =32) (225/231 =33) (232/238 =34) (239/245 =35) (246/252 =36) (253/259 =37) (260/266 =38) (267/273 =39) (274/280 =40) (281/287 =41) (288/294 =42) (295/301 =43) (302/308 =44) (309/315 =45) (316/322 =46) (323/329 =47) (330/336 =48) (337/343 =49) (344/350 =50) (351/357 =51) (358/364 =52)  (else=.), gen(elapsedweeks)
forvalues v=1/52 {
recode elapsedweeks (-`v'=1)(else=0), gen(priorweek`v')
}

forvalues v=1/52 {
recode elapsedweeks (`v'=1)(else=0), gen(postweek`v')
}

*****
*PARENT VARIABLES 
*****
egen gavebirth2016= rownonmiss(dob_B), strok
egen newmom= rownonmiss(dob_mom), strok
replace newmom=0 if newdad==1
replace newdad=0 if newmom==1|newdad~=1

*generating a new parent variable
gen newparent = 0
replace newparent = 2 if newmom==1
replace newparent = 1 if newdad==1
lab def newparent 0"not" 1"new dad" 2"new mom"
lab val newparent newparent

forvalues v =1/45 {
lab var priorweek`v' "`v' weeks prior"
}
forvalues v=1/8 {
lab var postweek`v' "`v' weeks post"
}
lab var electionday "Election Day"
lab var elapsedweeks "Weeks Before and After Election"
lab var elapseddays "Days Before and After Election"

lab var priorweek1 "1 week prior"
lab var postweek1 "1 week post"

//PARENT AGE 
*creating age variables 
gen yearborn = dob_year
destring yearborn, force replace
*note that this is going to be age in 2016 
gen age = 2016-yearborn
gen agesq = age^2

//TURNOUT VARIABLES
*tagging people who turned out in the 2016 election
gen turnout_g2016=0
replace turnout_g2016=1 if electiondate16R=="2016-11-08"

*tagging people who turned out in the 2014 election
gen turnout_g2014=0
replace turnout_g2014=1 if electiondate14R=="2014-11-04"

*tagging people who turnout out in the 2012 election 
gen turnout_g2012=0
replace turnout_g2012=1 if electiondate12R=="2012-11-06"

*tagging people who turned out in the 2010 election
gen turnout_g2010=0
replace turnout_g2010=1 if electiondate10R=="2010-11-02"

//INELIGIBILITY FOR VOTING IN 2012 AND 2016 DUE TO AGE
gen newdob=date(dob,"YMD")
disp date("1998-11-08", "YMD")
recode newdob (-99999/14191=0)(14192/25000=1)(else=.), gen(tooyoung16)
disp date("1994-11-06", "YMD")
recode newdob(-99999/12728=0)(12729/25000=1)(else=.), gen(tooyoung12)
replace tooyoung12 =1 if newdob>12728

//TURNOUT - TOO YOUNG
gen turnout_g2016r = turnout_g2016
replace turnout_g2016r = . if tooyoung16==1

gen turnout_g2012r = turnout_g2012
replace turnout_g2012r = 0 if tooyoung12==1

//COVARIATES
recode hisp_mom (1=0)(2/8=1)(9=0)(else=.), gen(hisp_mom_recoded)
recode race_mom_multi (1=1 "White")(2=2 "Black")(3=5 "American Indian")(4 5=4 "Asian")(6 7 9= 9 "Other/unknown")(else=.), gen(race5cat_mom)
replace race5cat_mom = 3 if hisp_mom_recoded==1
lab def race5cat_mom 3 "Hispanic", modify
recode race5cat_mom (2=1)(1 3/9=0)(else=.), gen(Black_Mom)
recode race5cat_mom (3=1)(1 2/9=0)(else=.), gen(Hisp_Mom)
recode race5cat_mom (4=1)(1 2 3/9=0)(else=.), gen(Asian_Mom)
recode race5cat_mom (5 9=1)(1 2 3 4 =0)(else=.), gen(Other_Mom)

recode hisp_dad (1=0)(2/8=1)(9=0)(else=.), gen(hisp_dad_recoded)
recode race_dad_multi (1=1 "White")(2=2 "Black")(3=5 "American Indian")(4 5=4 "Asian")(6 7 9= 9 "Other/unknown")(else=.), gen(race5cat_dad)
replace race5cat_dad = 3 if hisp_dad_recoded==1
lab def race5cat_dad 3 "Hispanic", modify
recode race5cat_dad (2=1)(1 3/9=0)(else=.), gen(Black_dad)
recode race5cat_dad (3=1)(1 2/9=0)(else=.), gen(Hisp_dad)
recode race5cat_dad (4=1)(1 2 3/9=0)(else=.), gen(Asian_dad)
recode race5cat_dad (5 9=1)(1 2 3 4 =0)(else=.), gen(Other_dad)

//setting race to the voter 
gen race5cat = race5cat_mom if newmom==1
replace race5cat = race5cat_dad if newdad==1
recode race5cat (2=1)(1 3/9=0)(else=.), gen(Black)
recode race5cat (3=1)(1 2/9=0)(else=.), gen(Hisp)
recode race5cat (4=1)(1 2 3/9=0)(else=.), gen(Asian)
recode race5cat (5 9=1)(1 2 3 4 =0)(else=.), gen(Other)
lab val race5cat race5cat_dad

//EDUCATION 
recode educ_mom (0 1 2 = 1 "Less HS") (3 4 5 6 7 8 9 = 0) (else=.), gen(educ_mom_no_hs)
recode educ_mom (3 = 1 "HS only") (0 1 2 4 5 6 7 8 9= 0) (else=.), gen(educ_mom_hs)
recode educ_mom (4 5 = 1 "Some College") (0 1 2 3 6 7 8 9= 0) (else=.), gen(educ_mom_some_college)
recode educ_mom (6 = 1 "College") (0 1 2 3 4 5 7 8 9= 0) (else=.), gen(educ_mom_college)
recode educ_mom (7 8 = 1 "Post Grad") (0 1 2 3 4 5 6 9= 0) (else=.), gen(educ_mom_postBA)
recode educ_mom (9 = 1 "Missing") (0 1 2 3 4 5 6 7 8= 0) (else=.), gen(educ_mom_missing)
recode educ_mom (0 1 2 = 1 "Less HS")(3=2 "HS only")(4 5=3 "Some College")(6=4 "College")(7 8 =5 "Post Grad")(9=9 "Missing"), gen(ed5cat_mom)
recode educ_mom (0 1 2 3 = 1 "HS or less")(4 5=2 "Some College")(6=3 "College")(7 8 =4 "Post Grad")(9=9 "Missing"), gen(ed4cat_mom)

recode educ_dad (0 1 2 = 1 "Less HS") (3 4 5 6 7 8 9 = 0) (else=.), gen(educ_dad_no_hs)
recode educ_dad (3 = 1 "HS only") (0 1 2 4 5 6 7 8 9= 0) (else=.), gen(educ_dad_hs)
recode educ_dad (4 5 = 1 "Some College") (0 1 2 3 6 7 8 9= 0) (else=.), gen(educ_dad_some_college)
recode educ_dad (6 = 1 "College") (0 1 2 3 4 5 7 8 9= 0) (else=.), gen(educ_dad_college)
recode educ_dad (7 8 = 1 "Post Grad") (0 1 2 3 4 5 6 9= 0) (else=.), gen(educ_dad_postBA)
recode educ_dad (9 = 1 "Missing") (0 1 2 3 4 5 6 7 8= 0) (else=.), gen(educ_dad_missing)
recode educ_dad (0 1 2 = 1 "Less HS")(3=2 "HS only")(4 5=3 "Some College")(6=4 "College")(7 8 =5 "Post Grad")(9=9 "Missing"), gen(ed5cat_dad)
recode educ_dad (0 1 2 3 = 1 "HS or less")(4 5=2 "Some College")(6=3 "College")(7 8 =4 "Post Grad")(9=9 "Missing"), gen(ed4cat_dad)

//setting education to the voter
foreach v in _no_hs _hs _some_college _college _postBA _missing {
gen educ`v'=educ_mom`v' if newmom==1
replace educ`v'=educ_dad`v' if newdad==1
}

//PARTY 
gen DEM=0
gen GOP=0
replace DEM = 1 if partycode=="DEM"
replace GOP= 1 if partycode=="REP"
//set no party or other party to baseline
gen pid3cata = 0
replace pid3cata = -1 if DEM==1
replace pid3cata = 1 if GOP==1
lab def pid3cata -1 "DEM" 0 "Other/None" 1 "GOP"
lab val pid3cata pid3cata


**********ANALYSIS*********
//BASIC MODEL
xi: reg turnout_g2016r turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if newmom==1
est store Mothers

xi: reg turnout_g2016r turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if newdad==1
est store Fathers 

**********FIGURE 1**********
coefplot Mothers Fathers, keep(priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7)  title(" 2016 Births: Mothers & Fathers") name("coefMF2016", replace) scale(.75) ysize(10) xsize(5) xline(0)
graph export "Figure1.tif", replace height(1200) width(600)

suest Mothers Fathers
test [Mothers_mean]electionday = [Fathers_mean]electionday
test [Mothers_mean]priorweek1 = [Fathers_mean]priorweek1
test [Mothers_mean]priorweek2 = [Fathers_mean]priorweek2
test [Mothers_mean]priorweek3 = [Fathers_mean]priorweek3
test [Mothers_mean]priorweek4 = [Fathers_mean]priorweek4
test [Mothers_mean]priorweek5 = [Fathers_mean]priorweek5
test [Mothers_mean]priorweek6 = [Fathers_mean]priorweek6
test [Mothers_mean]priorweek7 = [Fathers_mean]priorweek7
test [Mothers_mean]postweek1 = [Fathers_mean]postweek1

//PARENTS
xi: reg turnout_g2016r turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode 
est store Parents
**********APPENDIX FIGURE A2**********
coefplot Parents, keep(priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7)  title(" 2016 Births: Parents") name("coefparents2016", replace) scale(.75) ysize(10) xsize(5) xline(0)
graph export "Appendix_FigureA2.tif", replace height(1200) width(600)

**********APPENDIX TABLE A3**********
est table Parents Mothers Fathers, keep(age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP turnout_g2012r tooyoung12 ) b(%9.2f) se stats(N) style(col)
est table Parents Mothers Fathers, keep(age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP turnout_g2012r tooyoung12 ) b(%9.2f) star(.1 .05 .01) stats(N) style(col)


//ALTERNATIVE BASELINE: FIRST WEEK OF THE YEAR
xi: reg turnout_g2016r turnout_g2012r tooyoung12 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6 postweek7 postweek8  age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if newmom==1
est store Mothers

xi: reg turnout_g2016r turnout_g2012r tooyoung12 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6 postweek7 postweek8  age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if newdad==1
est store Fathers 

xi: reg turnout_g2016r turnout_g2012r tooyoung12 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6 postweek7 postweek8 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode 
est store Parents

**********APPENDIX FIGURE A3**********
coefplot Parents, keep(priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 postweek8)  title(" 2016 Births: Alternative Baseline") name("coefP2016", replace) scale(.75) ysize(10) xsize(5) xline(0)
graph export "Appendix_FigureA3a.tif", replace height(1200) width(600)

coefplot Mothers Fathers, keep(priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 postweek8)  title(" 2016 Births: Alternative Baseline, by Parent") name("coefMF2016", replace) scale(.75) ysize(10) xsize(5) xline(0)
graph export "Appendix_FigureA3b.tif", replace height(1200) width(600)


//PROBIT RESULTS
xi: probit turnout_g2016r turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode 
est store Parents

xi: probit turnout_g2016r turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if newmom==1
est store Mothers

xi: probit turnout_g2016r turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if newmom==0
est store Fathers

**********APPENDIX FIGURE A4**********
coefplot Parents, keep(priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7  )  title("2016 Births: Probit Results") name("probitcoef", replace) scale(.75) ysize(10) xsize(5) xline(0)
graph export "Appendix_FigureA4a.tif", replace height(1200) width(600)

coefplot Mothers Fathers, keep(priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7  )  title("2016 Births: Probit Results by Parent") name("probitcoefMF", replace) scale(.75) ysize(10) xsize(5) xline(0)
graph export "Appendix_FigureA4b.tif", replace height(1200) width(600)


//DAILY INDICATORS
forvalues v= 1(1)60 {
recode elapseddays (-`v'=1)(else=0), gen(daysbeforeelectionday`v')
lab var daysbeforeelectionday`v' "`v' days prior"
}

forval v=1/30 {
recode elapseddays (`v'=1) (else=0), gen(dayspostelectionday`v')
lab var dayspostelectionday`v' "`v' days post"
}

xi: reg turnout_g2016r turnout_g2012r tooyoung12 daysbeforeelectionday60 daysbeforeelectionday59 daysbeforeelectionday58 daysbeforeelectionday57 daysbeforeelectionday56 daysbeforeelectionday55 daysbeforeelectionday54 daysbeforeelectionday53 daysbeforeelectionday52 daysbeforeelectionday51 daysbeforeelectionday50 daysbeforeelectionday49 daysbeforeelectionday48 daysbeforeelectionday47 daysbeforeelectionday46 daysbeforeelectionday45 daysbeforeelectionday44 daysbeforeelectionday43 daysbeforeelectionday42 daysbeforeelectionday41 daysbeforeelectionday40 daysbeforeelectionday39 daysbeforeelectionday38 daysbeforeelectionday37 daysbeforeelectionday36 daysbeforeelectionday35 daysbeforeelectionday34 daysbeforeelectionday33 daysbeforeelectionday32 daysbeforeelectionday31 daysbeforeelectionday30 daysbeforeelectionday29 daysbeforeelectionday28 daysbeforeelectionday27 daysbeforeelectionday26 daysbeforeelectionday25 daysbeforeelectionday24 daysbeforeelectionday23 daysbeforeelectionday22 daysbeforeelectionday21 daysbeforeelectionday20 daysbeforeelectionday19 daysbeforeelectionday18 daysbeforeelectionday17 daysbeforeelectionday16 daysbeforeelectionday15 daysbeforeelectionday14 daysbeforeelectionday13 daysbeforeelectionday12 daysbeforeelectionday11 daysbeforeelectionday10 daysbeforeelectionday9 daysbeforeelectionday8 daysbeforeelectionday7 daysbeforeelectionday6 daysbeforeelectionday5 daysbeforeelectionday4 daysbeforeelectionday3 daysbeforeelectionday2 daysbeforeelectionday1 electionday dayspostelectionday1 dayspostelectionday2 dayspostelectionday3 dayspostelectionday4 dayspostelectionday5 dayspostelectionday6 dayspostelectionday7 dayspostelectionday8 dayspostelectionday9 dayspostelectionday10 dayspostelectionday11 dayspostelectionday12 dayspostelectionday13 dayspostelectionday14 dayspostelectionday15 dayspostelectionday16 dayspostelectionday17 dayspostelectionday18 dayspostelectionday19 dayspostelectionday20 dayspostelectionday21 dayspostelectionday22 dayspostelectionday23 dayspostelectionday24 dayspostelectionday25 dayspostelectionday26 dayspostelectionday27 dayspostelectionday28 dayspostelectionday29 dayspostelectionday30 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if elapseddays<61
est store Parents 
xi: reg turnout_g2016r turnout_g2012r tooyoung12 daysbeforeelectionday60 daysbeforeelectionday59 daysbeforeelectionday58 daysbeforeelectionday57 daysbeforeelectionday56 daysbeforeelectionday55 daysbeforeelectionday54 daysbeforeelectionday53 daysbeforeelectionday52 daysbeforeelectionday51 daysbeforeelectionday50 daysbeforeelectionday49 daysbeforeelectionday48 daysbeforeelectionday47 daysbeforeelectionday46 daysbeforeelectionday45 daysbeforeelectionday44 daysbeforeelectionday43 daysbeforeelectionday42 daysbeforeelectionday41 daysbeforeelectionday40 daysbeforeelectionday39 daysbeforeelectionday38 daysbeforeelectionday37 daysbeforeelectionday36 daysbeforeelectionday35 daysbeforeelectionday34 daysbeforeelectionday33 daysbeforeelectionday32 daysbeforeelectionday31 daysbeforeelectionday30 daysbeforeelectionday29 daysbeforeelectionday28 daysbeforeelectionday27 daysbeforeelectionday26 daysbeforeelectionday25 daysbeforeelectionday24 daysbeforeelectionday23 daysbeforeelectionday22 daysbeforeelectionday21 daysbeforeelectionday20 daysbeforeelectionday19 daysbeforeelectionday18 daysbeforeelectionday17 daysbeforeelectionday16 daysbeforeelectionday15 daysbeforeelectionday14 daysbeforeelectionday13 daysbeforeelectionday12 daysbeforeelectionday11 daysbeforeelectionday10 daysbeforeelectionday9 daysbeforeelectionday8 daysbeforeelectionday7 daysbeforeelectionday6 daysbeforeelectionday5 daysbeforeelectionday4 daysbeforeelectionday3 daysbeforeelectionday2 daysbeforeelectionday1 electionday dayspostelectionday1 dayspostelectionday2 dayspostelectionday3 dayspostelectionday4 dayspostelectionday5 dayspostelectionday6 dayspostelectionday7 dayspostelectionday8 dayspostelectionday9 dayspostelectionday10 dayspostelectionday11 dayspostelectionday12 dayspostelectionday13 dayspostelectionday14 dayspostelectionday15 dayspostelectionday16 dayspostelectionday17 dayspostelectionday18 dayspostelectionday19 dayspostelectionday20 dayspostelectionday21 dayspostelectionday22 dayspostelectionday23 dayspostelectionday24 dayspostelectionday25 dayspostelectionday26 dayspostelectionday27 dayspostelectionday28 dayspostelectionday29 dayspostelectionday30 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if elapseddays<61 & newmom==1
est store Mothers
xi: reg turnout_g2016r turnout_g2012r tooyoung12 daysbeforeelectionday60 daysbeforeelectionday59 daysbeforeelectionday58 daysbeforeelectionday57 daysbeforeelectionday56 daysbeforeelectionday55 daysbeforeelectionday54 daysbeforeelectionday53 daysbeforeelectionday52 daysbeforeelectionday51 daysbeforeelectionday50 daysbeforeelectionday49 daysbeforeelectionday48 daysbeforeelectionday47 daysbeforeelectionday46 daysbeforeelectionday45 daysbeforeelectionday44 daysbeforeelectionday43 daysbeforeelectionday42 daysbeforeelectionday41 daysbeforeelectionday40 daysbeforeelectionday39 daysbeforeelectionday38 daysbeforeelectionday37 daysbeforeelectionday36 daysbeforeelectionday35 daysbeforeelectionday34 daysbeforeelectionday33 daysbeforeelectionday32 daysbeforeelectionday31 daysbeforeelectionday30 daysbeforeelectionday29 daysbeforeelectionday28 daysbeforeelectionday27 daysbeforeelectionday26 daysbeforeelectionday25 daysbeforeelectionday24 daysbeforeelectionday23 daysbeforeelectionday22 daysbeforeelectionday21 daysbeforeelectionday20 daysbeforeelectionday19 daysbeforeelectionday18 daysbeforeelectionday17 daysbeforeelectionday16 daysbeforeelectionday15 daysbeforeelectionday14 daysbeforeelectionday13 daysbeforeelectionday12 daysbeforeelectionday11 daysbeforeelectionday10 daysbeforeelectionday9 daysbeforeelectionday8 daysbeforeelectionday7 daysbeforeelectionday6 daysbeforeelectionday5 daysbeforeelectionday4 daysbeforeelectionday3 daysbeforeelectionday2 daysbeforeelectionday1 electionday dayspostelectionday1 dayspostelectionday2 dayspostelectionday3 dayspostelectionday4 dayspostelectionday5 dayspostelectionday6 dayspostelectionday7 dayspostelectionday8 dayspostelectionday9 dayspostelectionday10 dayspostelectionday11 dayspostelectionday12 dayspostelectionday13 dayspostelectionday14 dayspostelectionday15 dayspostelectionday16 dayspostelectionday17 dayspostelectionday18 dayspostelectionday19 dayspostelectionday20 dayspostelectionday21 dayspostelectionday22 dayspostelectionday23 dayspostelectionday24 dayspostelectionday25 dayspostelectionday26 dayspostelectionday27 dayspostelectionday28 dayspostelectionday29 dayspostelectionday30 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if elapseddays<61 & newmom==0
est store Fathers 

**********APPENDIX FIGURE A5**********
coefplot Parents, keep(daysbeforeelectionday60 daysbeforeelectionday59 daysbeforeelectionday58 daysbeforeelectionday57 daysbeforeelectionday56 daysbeforeelectionday55 daysbeforeelectionday54 daysbeforeelectionday53 daysbeforeelectionday52 daysbeforeelectionday51 daysbeforeelectionday50 daysbeforeelectionday49 daysbeforeelectionday48 daysbeforeelectionday47 daysbeforeelectionday46 daysbeforeelectionday45 daysbeforeelectionday44 daysbeforeelectionday43 daysbeforeelectionday42 daysbeforeelectionday41 daysbeforeelectionday40 daysbeforeelectionday39 daysbeforeelectionday38 daysbeforeelectionday37 daysbeforeelectionday36 daysbeforeelectionday35 daysbeforeelectionday34 daysbeforeelectionday33 daysbeforeelectionday32 daysbeforeelectionday31 daysbeforeelectionday30 daysbeforeelectionday29 daysbeforeelectionday28 daysbeforeelectionday27 daysbeforeelectionday26 daysbeforeelectionday25 daysbeforeelectionday24 daysbeforeelectionday23 daysbeforeelectionday22 daysbeforeelectionday21 daysbeforeelectionday20 daysbeforeelectionday19 daysbeforeelectionday18 daysbeforeelectionday17 daysbeforeelectionday16 daysbeforeelectionday15 daysbeforeelectionday14 daysbeforeelectionday13 daysbeforeelectionday12 daysbeforeelectionday11 daysbeforeelectionday10 daysbeforeelectionday9 daysbeforeelectionday8 daysbeforeelectionday7 daysbeforeelectionday6 daysbeforeelectionday5 daysbeforeelectionday4 daysbeforeelectionday3 daysbeforeelectionday2 daysbeforeelectionday1 electionday dayspostelectionday1 dayspostelectionday2 dayspostelectionday3 dayspostelectionday4 dayspostelectionday5 dayspostelectionday6 dayspostelectionday7 dayspostelectionday8 dayspostelectionday9 dayspostelectionday10 dayspostelectionday11 dayspostelectionday12 dayspostelectionday13 dayspostelectionday14 dayspostelectionday15 dayspostelectionday16 dayspostelectionday17 dayspostelectionday18 dayspostelectionday19 dayspostelectionday20 dayspostelectionday21 dayspostelectionday22 dayspostelectionday23 dayspostelectionday24 dayspostelectionday25 dayspostelectionday26 dayspostelectionday27 dayspostelectionday28 dayspostelectionday29 dayspostelectionday30  )  title("2016 Births: Daily Indicators") name("dailyP", replace) scale(.75) ysize(10) xsize(5) xline(0)
graph export "Appendix_FigureA5a.tif", replace height(1200) width(600)


coefplot Mothers Fathers, keep(daysbeforeelectionday60 daysbeforeelectionday59 daysbeforeelectionday58 daysbeforeelectionday57 daysbeforeelectionday56 daysbeforeelectionday55 daysbeforeelectionday54 daysbeforeelectionday53 daysbeforeelectionday52 daysbeforeelectionday51 daysbeforeelectionday50 daysbeforeelectionday49 daysbeforeelectionday48 daysbeforeelectionday47 daysbeforeelectionday46 daysbeforeelectionday45 daysbeforeelectionday44 daysbeforeelectionday43 daysbeforeelectionday42 daysbeforeelectionday41 daysbeforeelectionday40 daysbeforeelectionday39 daysbeforeelectionday38 daysbeforeelectionday37 daysbeforeelectionday36 daysbeforeelectionday35 daysbeforeelectionday34 daysbeforeelectionday33 daysbeforeelectionday32 daysbeforeelectionday31 daysbeforeelectionday30 daysbeforeelectionday29 daysbeforeelectionday28 daysbeforeelectionday27 daysbeforeelectionday26 daysbeforeelectionday25 daysbeforeelectionday24 daysbeforeelectionday23 daysbeforeelectionday22 daysbeforeelectionday21 daysbeforeelectionday20 daysbeforeelectionday19 daysbeforeelectionday18 daysbeforeelectionday17 daysbeforeelectionday16 daysbeforeelectionday15 daysbeforeelectionday14 daysbeforeelectionday13 daysbeforeelectionday12 daysbeforeelectionday11 daysbeforeelectionday10 daysbeforeelectionday9 daysbeforeelectionday8 daysbeforeelectionday7 daysbeforeelectionday6 daysbeforeelectionday5 daysbeforeelectionday4 daysbeforeelectionday3 daysbeforeelectionday2 daysbeforeelectionday1 electionday dayspostelectionday1 dayspostelectionday2 dayspostelectionday3 dayspostelectionday4 dayspostelectionday5 dayspostelectionday6 dayspostelectionday7 dayspostelectionday8 dayspostelectionday9 dayspostelectionday10 dayspostelectionday11 dayspostelectionday12 dayspostelectionday13 dayspostelectionday14 dayspostelectionday15 dayspostelectionday16 dayspostelectionday17 dayspostelectionday18 dayspostelectionday19 dayspostelectionday20 dayspostelectionday21 dayspostelectionday22 dayspostelectionday23 dayspostelectionday24 dayspostelectionday25 dayspostelectionday26 dayspostelectionday27 dayspostelectionday28 dayspostelectionday29 dayspostelectionday30  )  title("2016 Births: Daily Indicators, by Parent") name("daily", replace) scale(.75) ysize(10) xsize(5) xline(0)
graph export "Appendix_FigureA5b.tif", replace height(1200) width(600)

**********REGRESSION DISCONTINUITY***********
*installing the packages that allow us to do this 
*ssc inst rdrobust
*ssc inst rd 

**********APPENDIX TABLE A4**********
preserve
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1)
restore
*optimal cutoff calculated as 12.942 - round to 13
preserve
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1) h(13)
restore 

*with covariates
preserve
drop if tooyoung16 == 1
 rdrobust turnout_g2016r elapseddays, c(1) p(1) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode)
 restore 
*optimal bandwidth for dads calculated at 11.046 - round to 11
preserve
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1) h(11) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode)
restore 

preserve
keep if newmom == 1
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode)
restore
*optimal bandwidth at 17.560 - round to 18
 preserve
keep if newmom == 1
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1) h(18) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode)
restore

preserve
keep if newdad == 1
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode)
restore 
*optimal bandwidth set at 13.857 - round to 14
preserve
keep if newdad == 1
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1) h(14) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode)
restore 
 
**********APPENDIX FIGURE A6**********
preserve 
keep if elapseddays < 12 & elapseddays > -10
tab elapseddays
rdplot turnout_g2016r elapseddays, c(1) p(1) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode) covs_eval(mean) ///
graph_options(title("All Parents") graphregion(color(white)) xtitle("Running Variable -- Days since Birth in Relation to Election Day") ytitle("Turnout") legend(off) yscale(r(0.4 0.8)) ylabel(.4 .45 .5 .55 .6 .65 .7 .75 .8))
graph export "Appendix_FigureA6.tif", replace 
restore 

**********APPENDIX FIGURE A7**********
preserve 
keep if elapseddays < 19 & elapseddays > -17
keep if newmom == 1
rdplot turnout_g2016r elapseddays, c(1) p(1) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode) covs_eval(mean) ///
graph_options(title("Moms Only") graphregion(color(white)) xtitle("Running Variable -- Days since Birth in Relation to Election Day") ytitle("Turnout") legend(off) yscale(r(0.4 0.8)) ylabel(.4 .45 .5 .55 .6 .65 .7 .75 .8) name(Moms_RDD, replace))
restore 

preserve 
keep if elapseddays < 15 & elapseddays > -13
keep if newdad == 1
rdplot turnout_g2016r elapseddays, c(1) p(1) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode) covs_eval(mean)  ///
graph_options(title("Dads Only") graphregion(color(white)) xtitle("Running Variable -- Days since Birth in Relation to Election Day") ytitle("Turnout") legend(off) yscale(r(0.4 0.8)) ylabel(.4 .45 .5 .55 .6 .65 .7 .75 .8) name(Dads_RDD, replace))
restore 
graph combine Moms_RDD Dads_RDD, ycommon xcommon 
graph export "Appendix_FigureA7.tif", replace height(600) width(1200)

**********APPENDIX TABLE A5**********
preserve
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1) h(49) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode)
restore 
preserve 
keep if newmom == 1
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1) h(49) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode)
restore 
preserve 
keep if newdad == 1
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1) h(49) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode)
restore
preserve
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1) h(7) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode)
restore 
preserve 
keep if newmom == 1
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1) h(7) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode)
restore 
preserve 
keep if newdad == 1
drop if tooyoung16 == 1
rdrobust turnout_g2016r elapseddays, c(1) p(1) h(7) covs(turnout_g2012r tooyoung12 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode)
restore


**********APPENDIX FIGURE A8**********
set scheme s1mono
twoway histogram elapseddays, discrete bcolor(gs9) subtitle("Density of Observations by Day") || function y = .0027, ra(elapseddays) clpat(dash) lcolor(black) xtitle(Elapsed Days) legend(off)
 graph export "Appendix_FigureA8.tif", replace

**********APPENDIX TABLE A6**********
*Doing some cleaning of the data before getting summary statistics 
recode elapsedweeks (-52/-8 1/8=0)(-7/0=1 "7 week window and EDay")(else=.), gen(window7ed)
recode ed4cat_dad (2/4=0)(1=1 "High School or Less")(else=.), gen(ed_hs_or_less_dad)
recode ed4cat_mom (2/4=0)(1=1 "High School or Less")(else=.), gen(ed_hs_or_less_mom)

*And getting summary statistics
*for sample statistics, dropping people who were too young to vote in 2016
*This will give us means inside and outside the 7 week window for mom education, dad education, Black, Hispanic, Asian, Dems, Turnout 2012, and too young in 2012
preserve
drop if tooyoung16==1
tabstat Black Hisp Asian DEM turnout_g2012 tooyoung12 ed_hs_or_less_dad ed_hs_or_less_mom, by(window7ed)
restore

*generating an age at birth variable
*First generating dob in the format i want
gen dob_new = date(dob,"YMD")
*and for the baby
gen dob_B_new = date(dob_B,"YMD")
*and generating 
gen age_at_birth = ((dob_B_new - dob_new)/365.25)

preserve
drop if tooyoung16==1
tabstat age_at_birth if newmom == 1, by(window7ed)
tabstat age_at_birth if newdad == 1, by(window7ed)
tab window7ed 
restore

**********DEMOGRAPHIC CHARACTERISTICS BY WEEK********
*create new version of weeks variable to remove the 0 to make it easier when we graph 
*I want to wrap Election Day up into T-1 week 
*If elapseddays == 0 I want elapsed weeks to be -1

gen elapsedweeks_new = elapsedweeks 
replace elapsedweeks_new = -1 if elapseddays == 0 

*In our analyses, we combine weeks 7 plus the few stray days in week 8 together, so doing that here as well
replace elapsedweeks_new = 7 if elapsedweeks==8

recode elapsedweeks_new (1=0)(2=1)(3=2)(4=3)(5=4)(6=5)(7=6), gen(elapsedweeksnozero)
*label this variable
lab def elapsedweeksnozero 0"1" 1"2" 2"3" 3"4" 4"5" 5"6" 6"7", modify
lab val elapsedweeksnozero elapsedweeksnozero 


*Now on to generating graphs 

**
*Mom age at time of baby birth 
**
preserve
drop if tooyoung16==1
collapse (mean) meanage = age_at_birth (sem) semage = age_at_birth if newmom == 1, by(elapsedweeksnozero )
serrbar meanage semage elapsedweeksnozero, scale(1.96) title("Mom's Age at Time of Baby's Birth") yline(31.1, lpattern(shortdash) lcolor(black)) ylab(29(1)33) ytitle("Mean (Age)") xtitle("Weeks from Election Day") xlab(-45 -35 -25 -15 -5 4, valuelabel) xline(-.5, lpattern(dash)) name(meanmomagebyweek, replace) scheme(s1mono) graphregion(color(white)) bgcolor(white) text(32.5 3.5 "Election Day", size(vsmall))
restore

**
*Dad age at time of baby birth 
**
preserve
drop if tooyoung16==1
collapse (mean) meanage = age_at_birth (sem) semage = age_at_birth if newdad == 1, by(elapsedweeksnozero)
serrbar meanage semage elapsedweeksnozero, scale(1.96) title("Dad's Age at Time of Baby's Birth") yline(34.2, lpattern(shortdash) lcolor(black)) ylab(32(1)36) ytitle("Mean (Age)") xtitle("Weeks from Election Day") xlab(-45 -35 -25 -15 -5 4, valuelabel) xline(-.5, lpattern(dash)) name(meandadagebyweek, replace) scheme(s1mono) graphregion(color(white)) bgcolor(white) text(35.5 3.5 "Election Day", size(vsmall))
restore 

**
*Mom education -- % HS or less
**
preserve
drop if tooyoung16==1
tabstat ed_hs_or_less_mom
restore
*.238

preserve 
drop if tooyoung16==1
collapse (mean) meanedmom = ed_hs_or_less_mom (sem) seedmom = ed_hs_or_less_mom, by(elapsedweeksnozero)
serrbar meanedmom seedmom elapsedweeksnozero, scale(1.96) title("Mom's Education (% High School or Less)") yline(.238, lpattern(shortdash) lcolor(black)) ytitle("% HS or Less") xtitle("Weeks from Election Day") xlab(-45 -35 -25 -15 -5 4, valuelabel) ylab (.1(.1).4) xline(-.5, lpattern(dash)) name(momedbyweek, replace) scheme(s1mono) graphregion(color(white)) bgcolor(white) text(.28 3.5 "Election Day", size(vsmall))
restore


**
*Dad education -- % HS or less
**

preserve
drop if tooyoung16==1
tabstat ed_hs_or_less_dad
restore
*.309

preserve
drop if tooyoung16==1
collapse (mean) meaneddad = ed_hs_or_less_dad (sem) seeddad = ed_hs_or_less_dad, by(elapsedweeksnozero)
serrbar meaneddad seeddad elapsedweeksnozero, scale(1.96) title("Dad's Education (% High School or Less)") yline(.309, lpattern(shortdash) lcolor(black)) ytitle("% HS or Less") xtitle("Weeks from Election Day") xlab(-45 -35 -25 -15 -5 4, valuelabel) ylab(.1(.1).4) xline(-.5, lpattern(dash))  name(dadedbyweek, replace) scheme(s1mono) graphregion(color(white))  bgcolor(white) text(.35 3.5 "Election Day", size(vsmall))
restore 

**
*African Americans
**

preserve
drop if tooyoung16==1
tabstat Black 
restore
*.052


preserve
drop if tooyoung16==1
collapse (mean) meanafam = Black (sem) seafam = Black, by(elapsedweeksnozero)
serrbar meanafam seafam elapsedweeksnozero, scale(1.96) title("African Americans") yline(.052, lpattern(shortdash) lcolor(black)) ytitle("Mean (African American)") xtitle("Weeks from Election Day") xlab(-45 -35 -25 -15 -5 4, valuelabel) ylab(.02(.02).09) name(meanafam, replace) xline(-.5, lpattern(dash)) scheme(s1mono) graphregion(color(white)) bgcolor(white) text(.07 3.5 "Election Day", size(vsmall))
restore

**
*Hispanic
**

preserve
drop if tooyoung16==1
tabstat Hisp
restore
*.367

preserve
drop if tooyoung16==1
collapse (mean) meanhisp = Hisp (sem) sehisp = Hisp, by(elapsedweeksnozero)
serrbar meanhisp sehisp elapsedweeksnozero, scale(1.96) title("Hispanics") yline(.367, lpattern(shortdash) lcolor(black)) ytitle("Mean (Hispnic)") xtitle("Weeks from Election Day") xlab(-45 -35 -25 -15 -5 4, valuelabel) ylab(.2(.1).5) name(meanhisp, replace) xline(-.5, lpattern(dash)) scheme(s1mono) graphregion(color(white)) bgcolor(white) text(.4 3.5 "Election Day", size(vsmall))
restore


**
*Asian Americans
**

preserve
drop if tooyoung16==1
tabstat Asian
restore
*.112

preserve
drop if tooyoung16==1
collapse (mean) meanaa = Asian (sem) seaa = Asian, by(elapsedweeksnozero)
serrbar meanaa seaa elapsedweeksnozero, scale(1.96) title("Asian Americans") yline(.112, lpattern(shortdash) lcolor(black)) ytitle("Mean (Asian)") xtitle("Weeks from Election Day") xlab(-45 -35 -25 -15 -5 4, valuelabel) ylab(0(.1).2) name(meanaa1, replace) scheme(s1mono) graphregion(color(white)) xline(-.5, lpattern(dash)) bgcolor(white) text(.15 3.5 "Election Day", size(vsmall))
restore


**
*Democrat
**

preserve
drop if tooyoung16==1
tabstat DEM
restore 

preserve
drop if tooyoung16==1
collapse (mean) meandem = DEM (sem) sedem = DEM, by(elapsedweeksnozero)
serrbar meandem sedem elapsedweeksnozero, scale(1.96) title("Democrats") yline(.410, lpattern(shortdash) lcolor(black)) ytitle("Mean (Democrat)") xtitle("Weeks from Election Day") xlab(-45 -35 -25 -15 -5 4, valuelabel) ylab(.3(.1).5) name(meandem2, replace) scheme(s1mono) graphregion(color(white)) bgcolor(white) xline(-.5, lpattern(dash)) text(.45 3.5 "Election Day", size(vsmall))
restore 

**
*Turnout 2012
**

preserve
drop if tooyoung16==1
tabstat turnout_g2012
restore


preserve
drop if tooyoung16==1
collapse (mean) meant12 = turnout_g2012 (sem) set12 = turnout_g2012, by(elapsedweeksnozero)
serrbar meant12 set12 elapsedweeksnozero, scale(1.96) title("Turnout 2012 ") yline(.490, lpattern(shortdash) lcolor(black)) ytitle("Mean (Turnout 2012)") xtitle("Weeks from Election Day") xlab(-45 -35 -25 -15 -5 4, valuelabel) ylab(.4(.1).6) name(meant12, replace) scheme(s1mono) graphregion(color(white)) bgcolor(white) xline(-.5, lpattern(dash)) text(.53 3.5 "Election Day", size(vsmall))
restore

**
*too young to vote in 2012
**
preserve
drop if tooyoung16==1
tabstat tooyoung12
restore
*.042

preserve
drop if tooyoung16==1
collapse (mean) meanty12 = tooyoung12 (sem) sety12 = tooyoung12, by(elapsedweeksnozero)
serrbar meanty12 sety12 elapsedweeksnozero, scale(1.96) title("Too Young to Vote in 2012") yline(.042, lpattern(shortdash) lcolor(black)) ytitle("Mean (Too Young to Vote 2012)") xtitle("Weeks from Election Day") xlab(-45 -35 -25 -15 -5 4, valuelabel) ylab(.01(.02).08) name(ty12, replace) xline(-.5, lpattern(dash)) scheme(s1mono) graphregion(color(white)) bgcolor(white) text(.06 3.5 "Election Day", size(vsmall))
restore


graph combine meanmomagebyweek meandadagebyweek, altshrink
graph export "Appendix_FigureA9_1.tif", replace height(900) width(1200)
graph combine momedbyweek dadedbyweek, altshrink
graph export "Appendix_FigureA9_2.tif", replace height(900) width(1200)
graph combine meanafam meanhisp, altshrink
graph export "Appendix_FigureA9_3.tif", replace height(900) width(1200)
graph combine meanaa1 meandem2, altshrink 
graph export "Appendix_FigureA9_4.tif", replace height(900) width(1200)
graph combine meant12 ty12, altshrink
graph export "Appendix_FigureA9_5.tif", replace height(900) width(1200)

//INSTITUTIONAL BUFFER
gen vbm2016=.
replace vbm2016=2 if method16=="VBM"|method16=="ERLY"
replace vbm2016=1 if method16=="POLL"
replace vbm2016=0 if turnout_g2016r==0
lab def vbm2016 0 "abstained" 1"Poll" 2"VBM"
lab val vbm2016 vbm2016
recode elapsedweeks (-52/-8 2/8=0)(-7/1=1 "8 week window")(else=.), gen(window)
recode countycode (2 32 46=1 "VBM ONLY")(1 3/31 33/45 47/58=0)(else=.), gen(VBMcounty_new)

//BY VBM IN 2012
gen pctvbm2012 =.
replace pctvbm2012=55.35 if countycode==1
replace pctvbm2012=100 if countycode==2
replace pctvbm2012=61.18 if countycode==3
replace pctvbm2012=61.9 if countycode==4
replace pctvbm2012=67.05 if countycode==5
replace pctvbm2012=55.81 if countycode==6
replace pctvbm2012=55.63 if countycode==7
replace pctvbm2012=59.23 if countycode==8
replace pctvbm2012=71.42 if countycode==9
replace pctvbm2012=54.31 if countycode==10
replace pctvbm2012=74.11 if countycode==11
replace pctvbm2012=51.95 if countycode==12
replace pctvbm2012=49.96 if countycode==13
replace pctvbm2012=63.58 if countycode==14
replace pctvbm2012=56.4 if countycode==15
replace pctvbm2012=75.82 if countycode==16
replace pctvbm2012=62.06 if countycode==17
replace pctvbm2012=74.96 if countycode==18
replace pctvbm2012=30.15 if countycode==19
replace pctvbm2012=61.17 if countycode==20
replace pctvbm2012=65.05 if countycode==21
replace pctvbm2012=58.08 if countycode==22
replace pctvbm2012=80.47 if countycode==23
replace pctvbm2012=52.67 if countycode==24
replace pctvbm2012=69.84 if countycode==25
replace pctvbm2012=59.87 if countycode==26
replace pctvbm2012=70.31 if countycode==27
replace pctvbm2012=89.16 if countycode==28
replace pctvbm2012=73.55 if countycode==29
replace pctvbm2012=51.29 if countycode==30
replace pctvbm2012=66.91 if countycode==31
replace pctvbm2012=71.05 if countycode==32
replace pctvbm2012=55.48 if countycode==33
replace pctvbm2012=58.62 if countycode==34
replace pctvbm2012=64.7 if countycode==35
replace pctvbm2012=48.05 if countycode==36
replace pctvbm2012=56.1 if countycode==37
replace pctvbm2012=52.95 if countycode==38
replace pctvbm2012=64.27 if countycode==39
replace pctvbm2012=63.27 if countycode==40
replace pctvbm2012=58.69 if countycode==41
replace pctvbm2012=58.91 if countycode==42
replace pctvbm2012=70.09 if countycode==43
replace pctvbm2012=53.06 if countycode==44
replace pctvbm2012=62.92 if countycode==45
replace pctvbm2012=100 if countycode==46
replace pctvbm2012=67.91 if countycode==47
replace pctvbm2012=57.22 if countycode==48
replace pctvbm2012=71.09 if countycode==49
replace pctvbm2012=68.25 if countycode==50
replace pctvbm2012=68.01 if countycode==51
replace pctvbm2012=65.47 if countycode==52
replace pctvbm2012=69.75 if countycode==53
replace pctvbm2012=59.97 if countycode==54
replace pctvbm2012=76.39 if countycode==55
replace pctvbm2012=49.92 if countycode==56
replace pctvbm2012=54.85 if countycode==57
replace pctvbm2012=58.68 if countycode==58

replace pctvbm2012 = . if countycode==2|countycode==32|countycode==46
replace pctvbm2012= pctvbm2012/100

foreach v of varlist priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7  {
gen vbm`v'=pctvbm2012*`v'
}

forvalues v=1/7 {
lab var vbmpostweek`v' "%VBM x `v' weeks post"
}

forvalues v=1/45 {
lab var vbmpriorweek`v' "%VBM x `v' weeks prior"
}

lab var vbmelectionday "%VBM x Election Day"

forvalues v=2/58 {
rename _Icountycod_`v' countycode`v'
}

//MOTHERS ONLY ANALYSIS, EXCLUDING BLANKET VBM COUNTIES
reg turnout_g2016r vbmp* vbmelectionday pctvbm turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode3-countycode31 countycode33-countycode45 countycode47-countycode56 if VBMcounty_new==0 & newmom==1
est store vbmp

capture postutil clear
tempfile priorresults
tempname memhold 
postfile `memhold' effect se pct priorweek using priorresults, replace
forvalues w=1(1)45 {
forvalues z=.3(.2).9 {
est restore vbmp
lincom priorweek`w' + `z'*vbmpriorweek`w'
post `memhold' (r(estimate)) (r(se)) (`z') (`w')
}
}
postclose `memhold​'

tempfile ED
tempname memhold 
postfile `memhold' effect se pct using ED, replace
forvalues z=.3(.2).9 {
est restore vbmp
lincom electionday + `z'*vbmelectionday
post `memhold' (r(estimate)) (r(se)) (`z')
}
postclose `memhold​'


tempfile afterresults2
tempname memhold 
postfile `memhold' effect se pct afterweek using afterresults2, replace
forvalues w=1(1)7 {
forvalues z=.3(.2).9 {
est restore vbmp
lincom postweek`w' + `z'*vbmpostweek`w'
post `memhold' (r(estimate)) (r(se)) (`z') (`w')
}
}
postclose `memhold​'

preserve
use priorresults, clear
gen w = -priorweek 
append using ED 
replace w = 0 if priorweek==.
append using afterresults2 
replace w = afterweek if w==.
table w pct, c(mean effect) 
gen LB = effect-invttail( 145423 ,.05)*se
gen UB = effect +invttail( 145423,.05)*se

lab def w -7 "7 weeks prior" -6 "6 weeks prior" -5 "5 weeks prior" -4 "4 weeks prior" -3 "3 weeks prior" -2 "2 weeks prior" -1 "1 week prior" 0"Election Day" 1 "1 week post", modify
lab val w w 

drop if pct>.4 & pct<.8
eclplot effect LB UB w if w>-8 & w<2, horizontal name(bygraph, replace) supby(pct) yscale(range(-7(1)1)) xline(0) title("Marginal Effect of Temporal Proximity of Birth" "Conditional on % VBM, Moms") ylabel(-7(1)1,valuelabel) ytitle("")  legend(order(2 - "" 4 - "")) legend(label(2 "30% VBM") label(4 "90% VBM")) xsize(4) ysize(6) scale(.75)
graph export "Figure2.tif", replace height(600) width(400)
restore

//MNL MODELS
recode vbm2016 (0=2 "Abstain")(1=0 "Poll")(2=1 "VBM"), gen(PollvVBMvAbstain2016)
xi: mlogit PollvVBMvAbstain2016 turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & VBMcounty_new==0, base(0)
est store PollvVBMvAbstain2016

recode vbm2016 (0=1 "Abstain")(1=0 "Poll")(2=2 "VBM"), gen(PollvAbstainvVBM2016)
xi: mlogit PollvAbstainvVBM2016 turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & VBMcounty_new==0, base(0)
est store PollvAbstainvVBM2016

coefplot (PollvVBMvAbstain2016, label("VBM vs. Polling Place")) (PollvAbstainvVBM2016, label("Abstain vs. Polling Place")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1) title("MNL Coefficient Estimates") xline(0) name(PollvVBMvAbstain, replace)

recode vbm2016 (0=0 "Abstain")(1=2 "Poll")(2=1 "VBM"), gen(newvbm2016)
xi: mlogit newvbm2016 turnout_g2012r tooyoung12 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7  postweek8 age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & VBMcounty_new==0, base(0)
est store newvbm2016

est restore newvbm2016
predict phat_abstain if e(sample), outcome(0)
predict phat_vbm if e(sample), outcome(1)
predict phat_poll if e(sample), outcome(2)
egen meanphat_abstain=mean(phat_abstain), by(elapsedweeks)
egen meanphat_vbm=mean(phat_vbm), by(elapsedweeks)
egen meanphat_poll=mean(phat_poll), by(elapsedweeks)
gen meanphat_noVBM_allowed = (meanphat_poll)/(meanphat_poll+meanphat_abstain)
table elapsedweeks, c(mean meanphat_noVBM_allowed)
gen meanphat_withVBM = (meanphat_poll+meanphat_vbm)

**********FIGURE 3**********
twoway (scatter meanphat_withVBM elapsedweeks if elapsedweeks<11, msymbol(O)) ///
(scatter meanphat_noVBM_allowed elapsedweeks if elapsedweeks<11, msymbol(T)) , ///
xscale(r(-40 10)) xlabel(-40(10)10) ///
ytitle("Pr(Turnout)") yscale(range(0(.2)1)) ///
name(noVBM, replace) legend(lab(1 "Current" ) lab(2 "No VBM Allowed")) ///
title("Turnout in a non-VBM World, Moms") 
graph combine PollvVBMvAbstain noVBM, row(1) ysize(5) xsize(9)
graph export "Figure3.tif", replace

//ROBUSTNESS CHECKS
//FN 6
reg turnout_g2016r vbmp* vbmelectionday pctvbm turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP  if VBMcounty_new==0 & newmom==1
est store nofixedeffects

reg turnout_g2016r vbmp* vbmelectionday pctvbm turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP median_age percent_white median_hh_i pct_nohs_18over if VBMcounty_new==0 & newmom==1
est store countycontrols
est table nofixedeffects countycontrols, keep(vbmelectionday electionday vbmpriorweek1 priorweek1 vbmpriorweek2 priorweek2 vbmpriorweek3 priorweek3 vbmpriorweek4 priorweek4 vbmpriorweek5 priorweek5 vbmpriorweek6 priorweek6 vbmpriorweek7 priorweek7 vbmpostweek1 postweek1) b(%9.2f) se

//HETEROGENEITY
//BY RACE 
xi: reg turnout_g2016r priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & race5cat_mom==1
est store white

xi: reg turnout_g2016r priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & race5cat_mom==2
est store black

xi: reg turnout_g2016r priorweek45  priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6 age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & race5cat_mom==3
est store Hispanic

xi: reg turnout_g2016r priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & race5cat_mom==4
est store Asian

**********APPENDIX FIGURE A11***********
coefplot (white, label("Non-Hispanic White")) (black, label("Black")) (Hispanic, label("Hispanic")) (Asian, label("Asian")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1) title("By Race") name(race_2016, replace) xline(0)
graph export "Appendix_FigureA11.tif", replace

//Tests of differences across race 
suest white black
forval x=1/7 {
test [white_mean]priorweek`x'= [black_mean]priorweek`x'
}
test [white_mean]electionday = [black_mean]electionday
test [white_mean]postweek1= [black_mean]postweek1

suest white Hispanic
forval x=1/7 {
test [white_mean]priorweek`x'= [Hispanic_mean]priorweek`x'
}
test [white_mean]electionday = [Hispanic_mean]electionday
test [white_mean]postweek1= [Hispanic_mean]postweek1

suest white Asian
forval x=1/7 {
test [white_mean]priorweek`x'= [Asian_mean]priorweek`x'
}
test [white_mean]electionday = [Asian_mean]electionday
test [white_mean]postweek1= [Asian_mean]postweek1

//BY EDUCATION OF MOTHER
forvalues x = 1/4 {
xi: reg turnout_g2016r turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & ed4cat_mom==`x'
est store MomEd_`x'
}
est table MomEd_1 MomEd_2 MomEd_3 MomEd_4, b(%9.2f) star(.05 .01 .001) stats(N) style(col) eq(1) keep(priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6 ) 

coefplot (MomEd_1, label("<=HS")) (MomEd_4, label(">BA")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1)  title("By Mom's Level of Education") name(MomEd_LO_HI_Ed, replace) xline(0)

//BY HIGHER EDUCATION LEVEL WITHIN-COUPLE
egen ed4cat_partnermax = rowmax(ed4cat_mom ed4cat_dad)
//about half of our sample appears to be pairs of people joined to the same baby
forvalues x = 1/4 {
xi: reg turnout_g2016r turnout_g2012r tooyoung12 priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & ed4cat_partnermax==`x'
est store CoupleEd_`x'
}
coefplot (CoupleEd_1, label("<=HS")) (CoupleEd_4, label(">BA")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1)  title("By Education, Couple's Maximum") name(CoupleEd_LO_HI_Ed, replace) xline(0)
**********APPENDIX FIGURE A12**********
graph combine MomEd_LO_HI_Ed CoupleEd_LO_HI_Ed
graph export "Appendix_FigureA12.tif", replace height(600) width(800) 

suest MomEd_1 MomEd_4 
forval x=1/7 {
test [MomEd_4_mean]priorweek`x'= [MomEd_1_mean]priorweek`x'
}
test [MomEd_4_mean]electionday = [MomEd_1_mean]electionday
test [MomEd_4_mean]postweek1= [MomEd_1_mean]postweek1

suest CoupleEd_1 CoupleEd_4 
forval x=1/7 {
test [CoupleEd_4_mean]priorweek`x'= [CoupleEd_1_mean]priorweek`x'
}
test [CoupleEd_4_mean]electionday = [CoupleEd_1_mean]electionday
test [CoupleEd_4_mean]postweek1= [CoupleEd_1_mean]postweek1

//BY WHETHER TURNED OUT IN 2012
forvalues x = 0/1 {
xi: reg turnout_g2016r priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6 age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & turnout_g2012r==`x'
est store voted12_`x'
}
**********APPENDIX FIGURE A13**********
coefplot (voted12_0, label("Did Not Vote in 2012")) (voted12_1, label("Voted in 2012")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1) title("By Turnout in 2012") name(voted12, replace) xline(0)
graph export "Appendix_FigureA13.tif", replace height(600) width(900)

suest voted12_1 voted12_0
forval x=1/7 {
test [voted12_1_mean]priorweek`x'= [voted12_0_mean]priorweek`x'
}
test [voted12_1_mean]electionday = [voted12_0_mean]electionday
test [voted12_1_mean]postweek1= [voted12_0_mean]postweek1


//BY PID
xi: reg turnout_g2016r priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & DEM==1
est store DEM
xi: reg turnout_g2016r priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & partycode=="NPP"
est store NPP
xi: reg turnout_g2016r priorweek45 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & GOP==1
est store GOP
**********APPENDIX FIGURE A14**********
coefplot (DEM, label("DEM")) (NPP, label("No Party")) (GOP, label("GOP")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1) title("By Party") name(pid_2016, replace) xline(0) legend(row(1))
graph export "Appendix_FigureA14.tif", replace

suest DEM GOP
forval x=1/7 {
test [DEM_mean]priorweek`x'= [GOP_mean]priorweek`x'
}
test [DEM_mean]electionday = [GOP_mean]electionday
test [DEM_mean]postweek1= [GOP_mean]postweek1

suest DEM NPP
forval x=1/7 {
test [DEM_mean]priorweek`x'= [NPP_mean]priorweek`x'
}
test [DEM_mean]electionday = [NPP_mean]electionday
test [DEM_mean]postweek1= [NPP_mean]postweek1

suest GOP NPP
forval x=1/7 {
test [GOP_mean]priorweek`x'= [NPP_mean]priorweek`x'
}
test [GOP_mean]electionday = [NPP_mean]electionday
test [GOP_mean]postweek1= [NPP_mean]postweek1

graph drop _all
**********ADDITIONAL DATASETS**********
**********PLACEBO TEST, 2017***********
use "deidentified_2016 and 2017.dta", clear 

*****Analyzing 2017 births as a baseline
gen dategen2016 = date("11/08/16","MDY",2016)
*generate elapsed days between birth and election day
gen dob_B_year = substr(dob_B, 1, 4)
gen dob_B_month = substr(dob_B, 5, 2)
gen dob_B_day = substr(dob_B, 7, 2)
egen dob_B_newformat = concat(dob_B_month dob_B_day dob_B_year)
gen baby_dob_DATE=date(dob_B_newformat, "MDY")
gen elapseddays = baby_dob_DATE-dategen2016

recode elapseddays (-365/-336=-12 "12 months prior")(-335/-305=-11 "11 months prior")(-304/-274=-10 "10 months prior")(-273/-245 = -9 "9 months prior") ///
	(-244/-214 =-8 "8 months prior")(-213/-184=-7 "7 months prior")(-183/-153=-6 "6 months prior")(-152/-123=-5 "5 months prior")(-122/-92=-4 "4 months prior") ///
	(-91/-61=-3 "3 months prior")(-60/-31 = -2 "2 months prior")(-30/-1 =-1 "1 month prior")(0=0 "Election Day")(1/30=1 "1 month post")(31/61=2 "2 months post") ///
	(63/92=3 "3 months post")(93/120=4 "4 months post")(121/151=5 "5 months post")(152/181=6 "6 months post")(182/212=7 "7 months post")(213/242=8 "8 months post") ///
	(243/273=9 "9 months post")(274/304=10 "10 months post")(305/334 = 11 "11 months post")(335/365=12 "12 months post")(366/418=13 "13+ months post")(else=.), gen(elapsedmonths)
lab var elapsedmonths "Months prior and post election"

forvalues v = 1/12 {
recode elapsedmonths (-`v'=1)(else=0), gen(priormonth`v')
}

forvalues v =1/13 {
recode elapsedmonths (`v'=1)(else=0), gen(postmonth`v')
}
recode elapsedmonths (0=1)(else=0), gen(electionday)


*Weekly variables
recode elapseddays (-364/-358 =-52) (-357/-351 =-51) (-350/-344 =-50) (-343/-337 =-49) (-336/-330 =-48) (-329/-323 =-47) (-322/-316 =-46) (-315/-309 =-45) (-308/-302 =-44) (-301/-295 =-43) (-294/-288 =-42) (-287/-281 =-41) (-280/-274 =-40) (-273/-267 =-39) (-266/-260 =-38) (-259/-253 =-37) (-252/-246 =-36) (-245/-239 =-35) (-238/-232 =-34) (-231/-225 =-33) (-224/-218 =-32) (-217/-211 =-31) (-210/-204 =-30) (-203/-197 =-29) (-196/-190 =-28) (-189/-183 =-27) (-182/-176 =-26) (-175/-169 =-25) (-168/-162 =-24) (-161/-155 =-23) (-154/-148 =-22) (-147/-141 =-21) (-140/-134 =-20) (-133/-127 =-19) (-126/-120 =-18) (-119/-113 =-17) (-112/-106 =-16) (-105/-99 =-15) (-98/-92 =-14) (-91/-85 =-13) (-84/-78 =-12) (-77/-71 =-11) (-70/-64 =-10) (-63/-57 =-9) (-56/-50 =-8) (-49/-43 =-7) (-42/-36 =-6) (-35/-29 =-5) (-28/-22 =-4) (-21/-15 =-3) (-14/-8 =-2) (-7/-1 =-1) (0=0) (1/7 =1) (8/14 =2) (15/21 =3) (22/28 =4) (29/35 =5) (36/42 =6) (43/49 =7) (50/56 =8) (57/63 =9) (64/70 =10) (71/77 =11) (78/84 =12) (85/91 =13) (92/98 =14) (99/105 =15) (106/112 =16) (113/119 =17) (120/126 =18) (127/133 =19) (134/140 =20) (141/147 =21) (148/154 =22) (155/161 =23) (162/168 =24) (169/175 =25) (176/182 =26) (183/189 =27) (190/196 =28) (197/203 =29) (204/210 =30) (211/217 =31) (218/224 =32) (225/231 =33) (232/238 =34) (239/245 =35) (246/252 =36) (253/259 =37) (260/266 =38) (267/273 =39) (274/280 =40) (281/287 =41) (288/294 =42) (295/301 =43) (302/308 =44) (309/315 =45) (316/322 =46) (323/329 =47) (330/336 =48) (337/343 =49) (344/350 =50) (351/357 =51) (358/364 =52)(365/371 =53)(372/378 =54)(379/385 =55)(386/392 =56)(393/399 =57)(400/406 =58)(407/413 =59)(414/418 =60)  (else=.), gen(elapsedweeks)
forvalues v=1/52 {
recode elapsedweeks (-`v'=1)(else=0), gen(priorweek`v')
}

forvalues v=1/60 {
recode elapsedweeks (`v'=1)(else=0), gen(postweek`v')
}

*****
*PARENT VARIABLES 
*****
gen gavebirth2016= 1 if dob_B_year=="2016"
replace gavebirth2016 = 0 if dob_B_year=="2017"
tab gavebirth2016

egen newmom= rownonmiss(dob_mom), strok
replace newmom=0 if newdad==1
replace newdad=0 if newmom==1|newdad~=1

*generating a new parent variable
gen newparent = 0
replace newparent = 2 if newmom==1
replace newparent = 1 if newdad==1
lab def newparent 0"not" 1"new dad" 2"new mom"
lab val newparent newparent

forvalues v =1/12 {
lab var priormonth`v' "`v' months prior"
lab var postmonth`v' "`v' months post"
}
forvalues v =1/45 {
lab var priorweek`v' "`v' weeks prior"
}
forvalues v=1/60 {
lab var postweek`v' "`v' weeks post"
}
lab var electionday "Election Day"
lab var elapsedweeks "Weeks Before and After Election"
lab var elapseddays "Days Before and After Election"

//AGE VARIABLES
*creating age variables 
gen yearborn = dob_year
destring yearborn, force replace
*note that this is going to be age in 2016 
gen age = 2016-yearborn
gen agesq = age^2

//TURNOUT VARIABLES
*tagging people who turned out in the 2016 election
gen turnout_g2016=0
replace turnout_g2016=1 if electiondate16R=="2016-11-08"

*tagging people who turned out in the 2014 election
gen turnout_g2014=0
replace turnout_g2014=1 if electiondate14R=="2014-11-04"

*tagging people who turnout out in the 2012 election 
gen turnout_g2012=0
replace turnout_g2012=1 if electiondate12R=="2012-11-06"

*tagging people who turned out in the 2010 election
gen turnout_g2010=0
replace turnout_g2010=1 if electiondate10R=="2010-11-02"

//INELIGIBILITY FOR VOTING IN 2012 AND 2016 DUE TO AGE
//turnout in 2012: those who were too young are currently just listed as 0
//need to dummy them out
//also set to missing those who were too young to vote in 2016
gen newdob=date(dob,"YMD")
disp date("1998-11-08", "YMD")
recode newdob (-99999/14191=0)(14192/25000=1)(else=.), gen(tooyoung16)
disp date("1994-11-06", "YMD")
recode newdob(-99999/12728=0)(12729/25000=1)(else=.), gen(tooyoung12)
replace tooyoung12 =1 if newdob>12728

gen turnout_g2016r = turnout_g2016
replace turnout_g2016r = . if tooyoung16==1

gen turnout_g2012r = turnout_g2012
replace turnout_g2012r = 0 if tooyoung12==1
//include tooyoung12 as a covariate when we control for turnout in 2012

//PREPPING COVARIATES
//RACE & ETHNICITY (PROVISIONAL CODING)
recode hisp_mom (1=0)(2/8=1)(9=0)(else=.), gen(hisp_mom_recoded)
recode race_mom_multi (1=1 "White")(2=2 "Black")(3=5 "American Indian")(4 5=4 "Asian")(6 7 9= 9 "Other/unknown")(else=.), gen(race5cat_mom)
replace race5cat_mom = 3 if hisp_mom_recoded==1
lab def race5cat_mom 3 "Hispanic", modify
recode race5cat_mom (2=1)(1 3/9=0)(else=.), gen(Black_Mom)
recode race5cat_mom (3=1)(1 2/9=0)(else=.), gen(Hisp_Mom)
recode race5cat_mom (4=1)(1 2 3/9=0)(else=.), gen(Asian_Mom)
recode race5cat_mom (5 9=1)(1 2 3 4 =0)(else=.), gen(Other_Mom)
//set NHW to baseline
tab race5cat_mom 
//we can look at the racial profile of the moms that we have matched.  42% are NHW, 34% H, 13% Asian, 4% Black

recode hisp_dad (1=0)(2/8=1)(9=0)(else=.), gen(hisp_dad_recoded)
recode race_dad_multi (1=1 "White")(2=2 "Black")(3=5 "American Indian")(4 5=4 "Asian")(6 7 9= 9 "Other/unknown")(else=.), gen(race5cat_dad)
replace race5cat_dad = 3 if hisp_dad_recoded==1
lab def race5cat_dad 3 "Hispanic", modify
recode race5cat_dad (2=1)(1 3/9=0)(else=.), gen(Black_dad)
recode race5cat_dad (3=1)(1 2/9=0)(else=.), gen(Hisp_dad)
recode race5cat_dad (4=1)(1 2 3/9=0)(else=.), gen(Asian_dad)
recode race5cat_dad (5 9=1)(1 2 3 4 =0)(else=.), gen(Other_dad)
//set NHW to baseline
tab race5cat_dad 

//setting race to the voter 
gen race5cat = race5cat_mom if newmom==1
replace race5cat = race5cat_dad if newdad==1
recode race5cat (2=1)(1 3/9=0)(else=.), gen(Black)
recode race5cat (3=1)(1 2/9=0)(else=.), gen(Hisp)
recode race5cat (4=1)(1 2 3/9=0)(else=.), gen(Asian)
recode race5cat (5 9=1)(1 2 3 4 =0)(else=.), gen(Other)
lab val race5cat race5cat_dad

//EDUCATION (PROVISIONAL CODING)
recode educ_mom (0 1 2 = 1 "Less HS") (3 4 5 6 7 8 9 = 0) (else=.), gen(educ_mom_no_hs)
recode educ_mom (3 = 1 "HS only") (0 1 2 4 5 6 7 8 9= 0) (else=.), gen(educ_mom_hs)
recode educ_mom (4 5 = 1 "Some College") (0 1 2 3 6 7 8 9= 0) (else=.), gen(educ_mom_some_college)
recode educ_mom (6 = 1 "College") (0 1 2 3 4 5 7 8 9= 0) (else=.), gen(educ_mom_college)
recode educ_mom (7 8 = 1 "Post Grad") (0 1 2 3 4 5 6 9= 0) (else=.), gen(educ_mom_postBA)
recode educ_mom (9 = 1 "Missing") (0 1 2 3 4 5 6 7 8= 0) (else=.), gen(educ_mom_missing)
recode educ_mom (0 1 2 = 1 "Less HS")(3=2 "HS only")(4 5=3 "Some College")(6=4 "College")(7 8 =5 "Post Grad")(9=9 "Missing"), gen(ed5cat_mom)
recode educ_mom (0 1 2 3 = 1 "HS or less")(4 5=2 "Some College")(6=3 "College")(7 8 =4 "Post Grad")(9=9 "Missing"), gen(ed4cat_mom)

recode educ_dad (0 1 2 = 1 "Less HS") (3 4 5 6 7 8 9 = 0) (else=.), gen(educ_dad_no_hs)
recode educ_dad (3 = 1 "HS only") (0 1 2 4 5 6 7 8 9= 0) (else=.), gen(educ_dad_hs)
recode educ_dad (4 5 = 1 "Some College") (0 1 2 3 6 7 8 9= 0) (else=.), gen(educ_dad_some_college)
recode educ_dad (6 = 1 "College") (0 1 2 3 4 5 7 8 9= 0) (else=.), gen(educ_dad_college)
recode educ_dad (7 8 = 1 "Post Grad") (0 1 2 3 4 5 6 9= 0) (else=.), gen(educ_dad_postBA)
recode educ_dad (9 = 1 "Missing") (0 1 2 3 4 5 6 7 8= 0) (else=.), gen(educ_dad_missing)
recode educ_dad (0 1 2 = 1 "Less HS")(3=2 "HS only")(4 5=3 "Some College")(6=4 "College")(7 8 =5 "Post Grad")(9=9 "Missing"), gen(ed5cat_dad)
recode educ_dad (0 1 2 3 = 1 "HS or less")(4 5=2 "Some College")(6=3 "College")(7 8 =4 "Post Grad")(9=9 "Missing"), gen(ed4cat_dad)

//setting education to the voter
foreach v in _no_hs _hs _some_college _college _postBA _missing {
gen educ`v'=educ_mom`v' if newmom==1
replace educ`v'=educ_dad`v' if newdad==1
}

//PARTY 
gen DEM=0
gen GOP=0
replace DEM = 1 if partycode=="DEM"
replace GOP= 1 if partycode=="REP"
//set no party or other party to baseline
gen pid3cata = 0
replace pid3cata = -1 if DEM==1
replace pid3cata = 1 if GOP==1
lab def pid3cata -1 "DEM" 0 "Other/None" 1 "GOP"
lab val pid3cata pid3cata
tab pid3cata race5cat, col

//compare everyone to those who had babies in 2017 
//placebo test: Figure 1 but with 2017 births
xi: reg turnout_g2016r turnout_g2012r tooyoung12 postweek9-postweek59 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if gavebirth2016==0
est store parents2017
xi: reg turnout_g2016r turnout_g2012r tooyoung12 postweek9-postweek59 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if gavebirth2016==0 & newmom==1
est store Mothers2017
xi: reg turnout_g2016r turnout_g2012r tooyoung12 postweek9-postweek59 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if gavebirth2016==0 & newmom==0
est store Fathers2017

coefplot parents2017, keep(postweek9 postweek10 postweek11 postweek12 postweek13 postweek14 postweek15 postweek16 postweek17 postweek18 postweek19 postweek20 postweek21 postweek22 postweek23 postweek24 postweek25 postweek26 postweek27 postweek28 postweek29 postweek30 postweek31 postweek32 postweek33 postweek34 postweek35 postweek36 postweek37 postweek38 postweek39 postweek40 postweek41 postweek42 postweek43 postweek44 postweek45 postweek46 postweek47 postweek48 postweek49 postweek50 postweek51 postweek52 postweek53 postweek54 postweek55 postweek56 postweek57 postweek58 postweek59 )  title("2017 Births") name("coefparents2017", replace) scale(.75) ysize(10) xsize(5) xline(0) 
graph export "Appendix_FigureA10a.tif", replace height(1200) width(600)

coefplot Mothers2017 Fathers2017, keep(postweek9 postweek10 postweek11 postweek12 postweek13 postweek14 postweek15 postweek16 postweek17 postweek18 postweek19 postweek20 postweek21 postweek22 postweek23 postweek24 postweek25 postweek26 postweek27 postweek28 postweek29 postweek30 postweek31 postweek32 postweek33 postweek34 postweek35 postweek36 postweek37 postweek38 postweek39 postweek40 postweek41 postweek42 postweek43 postweek44 postweek45 postweek46 postweek47 postweek48 postweek49 postweek50 postweek51 postweek52 postweek53 postweek54 postweek55 postweek56 postweek57 postweek58 postweek59 )  title("2017 Births, by Parent") name("coefparents2017", replace) scale(.75) ysize(10) xsize(5) xline(0) 
graph export "Appendix_FigureA10b.tif", replace height(1200) width(600)

graph drop _all

**********2012 ANALYSIS**********
use "deidentified_2012.dta", clear 
gen dategen2012 = date("11/06/12","MDY",2012)
gen dob_B_year = substr(dob_B, 1, 4)
gen dob_B_month = substr(dob_B, 5, 2)
gen dob_B_day = substr(dob_B, 7, 2)
egen dob_B_newformat = concat(dob_B_month dob_B_day dob_B_year)
gen baby_dob_DATE=date(dob_B_newformat, "MDY")
gen elapseddays = baby_dob_DATE-dategen2012

*Weekly variables
recode elapseddays (-364/-358 =-52) (-357/-351 =-51) (-350/-344 =-50) (-343/-337 =-49) (-336/-330 =-48) (-329/-323 =-47) (-322/-316 =-46) (-315/-309 =-45) (-308/-302 =-44) (-301/-295 =-43) (-294/-288 =-42) (-287/-281 =-41) (-280/-274 =-40) (-273/-267 =-39) (-266/-260 =-38) (-259/-253 =-37) (-252/-246 =-36) (-245/-239 =-35) (-238/-232 =-34) (-231/-225 =-33) (-224/-218 =-32) (-217/-211 =-31) (-210/-204 =-30) (-203/-197 =-29) (-196/-190 =-28) (-189/-183 =-27) (-182/-176 =-26) (-175/-169 =-25) (-168/-162 =-24) (-161/-155 =-23) (-154/-148 =-22) (-147/-141 =-21) (-140/-134 =-20) (-133/-127 =-19) (-126/-120 =-18) (-119/-113 =-17) (-112/-106 =-16) (-105/-99 =-15) (-98/-92 =-14) (-91/-85 =-13) (-84/-78 =-12) (-77/-71 =-11) (-70/-64 =-10) (-63/-57 =-9) (-56/-50 =-8) (-49/-43 =-7) (-42/-36 =-6) (-35/-29 =-5) (-28/-22 =-4) (-21/-15 =-3) (-14/-8 =-2) (-7/-1 =-1) (0=0) (1/7 =1) (8/14 =2) (15/21 =3) (22/28 =4) (29/35 =5) (36/42 =6) (43/49 =7) (50/56 =8) (57/63 =9) (64/70 =10) (71/77 =11) (78/84 =12) (85/91 =13) (92/98 =14) (99/105 =15) (106/112 =16) (113/119 =17) (120/126 =18) (127/133 =19) (134/140 =20) (141/147 =21) (148/154 =22) (155/161 =23) (162/168 =24) (169/175 =25) (176/182 =26) (183/189 =27) (190/196 =28) (197/203 =29) (204/210 =30) (211/217 =31) (218/224 =32) (225/231 =33) (232/238 =34) (239/245 =35) (246/252 =36) (253/259 =37) (260/266 =38) (267/273 =39) (274/280 =40) (281/287 =41) (288/294 =42) (295/301 =43) (302/308 =44) (309/315 =45) (316/322 =46) (323/329 =47) (330/336 =48) (337/343 =49) (344/350 =50) (351/357 =51) (358/364 =52)  (else=.), gen(elapsedweeks)
forvalues v=1/52 {
recode elapsedweeks (-`v'=1)(else=0), gen(priorweek`v')
}
forvalues v=1/52 {
recode elapsedweeks (`v'=1)(else=0), gen(postweek`v')
}
forvalues v =1/45 {
lab var priorweek`v' "`v' weeks prior"
}
forvalues v=1/8 {
lab var postweek`v' "`v' weeks post"
}
gen electionday=0
replace electionday=1 if elapseddays==0
lab var electionday "Election Day"
lab var elapsedweeks "Weeks Before and After Election"
lab var elapseddays "Days Before and After Election"
//week 45 is very short - only two days. combine with week 44
replace priorweek44=1 if priorweek45==1


*****
*PARENT VARIABLES 
*****
egen gavebirth2012= rownonmiss(dob_B), strok
egen newmom= rownonmiss(dob_mom), strok
replace newmom=0 if newdad==1
replace newdad=0 if newmom==1|newdad~=1

*generating a new parent variable
gen newparent = 0
replace newparent = 2 if newmom==1
replace newparent = 1 if newdad==1
lab def newparent 0"not" 1"new dad" 2"new mom"
lab val newparent newparent

//AGE VARIABLES
*creating age variables 
gen yearborn = dob_year
destring yearborn, force replace
*note that this is going to be age in 2012
gen age = 2012-yearborn
gen agesq = age^2

//TURNOUT VARIABLES
*tagging people who turnout out in the 2012 election 
gen turnout_g2012=0
replace turnout_g2012=1 if electiondate12R=="2012-11-06"

*tagging people who turned out in the 2010 election
gen turnout_g2010=0
replace turnout_g2010=1 if electiondate10R=="2010-11-02"

gen turnout_g2008=0
replace turnout_g2008=1 if electiondate8=="2008-11-04"


//INELIGIBILITY FOR VOTING IN 2012 AND 2016 DUE TO AGE
//turnout in 2012: those who were too young are currently just listed as 0
//need to dummy them out
//also set to missing those who were too young to vote in 2016
gen newdob=date(dob,"YMD")
disp date("1998-11-08", "YMD")
recode newdob (-99999/14191=0)(14192/25000=1)(else=.), gen(tooyoung16)
disp date("1994-11-06", "YMD")
recode newdob(-99999/12728=0)(12729/25000=1)(else=.), gen(tooyoung12)
replace tooyoung12 =1 if newdob>12728

disp date("1990-11-04", "YMD")
recode newdob(-99999/11265=0)(11266/25000=1)(else=.), gen(tooyoung08)
replace tooyoung08 =1 if newdob>11265

gen turnout_g2012r = turnout_g2012
replace turnout_g2012r = . if tooyoung12==1

gen turnout_g2008r = turnout_g2008
replace turnout_g2008r = . if tooyoung08==1
//include tooyoung08 with turnout_g2008 as a covariate when we model turnout in 2012

//PREPPING COVARIATES
//RACE & ETHNICITY 
recode hisp_mom (1=0)(2/8=1)(9=0)(else=.), gen(hisp_mom_recoded)
recode race_mom_multi (1=1 "White")(2=2 "Black")(3=5 "American Indian")(4 5=4 "Asian")(6 7 9= 9 "Other/unknown")(else=.), gen(race5cat_mom)
replace race5cat_mom = 3 if hisp_mom_recoded==1
lab def race5cat_mom 3 "Hispanic", modify
recode race5cat_mom (2=1)(1 3/9=0)(else=.), gen(Black_Mom)
recode race5cat_mom (3=1)(1 2/9=0)(else=.), gen(Hisp_Mom)
recode race5cat_mom (4=1)(1 2 3/9=0)(else=.), gen(Asian_Mom)
recode race5cat_mom (5 9=1)(1 2 3 4 =0)(else=.), gen(Other_Mom)
//set NHW to baseline
tab race5cat_mom 
//we can look at the racial profile of the moms that we have matched.  42% are NHW, 34% H, 13% Asian, 4% Black

recode hisp_dad (1=0)(2/8=1)(9=0)(else=.), gen(hisp_dad_recoded)
recode race_dad_multi (1=1 "White")(2=2 "Black")(3=5 "American Indian")(4 5=4 "Asian")(6 7 9= 9 "Other/unknown")(else=.), gen(race5cat_dad)
replace race5cat_dad = 3 if hisp_dad_recoded==1
lab def race5cat_dad 3 "Hispanic", modify
recode race5cat_dad (2=1)(1 3/9=0)(else=.), gen(Black_dad)
recode race5cat_dad (3=1)(1 2/9=0)(else=.), gen(Hisp_dad)
recode race5cat_dad (4=1)(1 2 3/9=0)(else=.), gen(Asian_dad)
recode race5cat_dad (5 9=1)(1 2 3 4 =0)(else=.), gen(Other_dad)
//set NHW to baseline

//setting race to the voter 
gen race5cat = race5cat_mom if newmom==1
replace race5cat = race5cat_dad if newdad==1
recode race5cat (2=1)(1 3/9=0)(else=.), gen(Black)
recode race5cat (3=1)(1 2/9=0)(else=.), gen(Hisp)
recode race5cat (4=1)(1 2 3/9=0)(else=.), gen(Asian)
recode race5cat (5 9=1)(1 2 3 4 =0)(else=.), gen(Other)
lab val race5cat race5cat_dad

//EDUCATION
recode educ_mom (0 1 2 = 1 "Less HS") (3 4 5 6 7 8 9 = 0) (else=.), gen(educ_mom_no_hs)
recode educ_mom (3 = 1 "HS only") (0 1 2 4 5 6 7 8 9= 0) (else=.), gen(educ_mom_hs)
recode educ_mom (4 5 = 1 "Some College") (0 1 2 3 6 7 8 9= 0) (else=.), gen(educ_mom_some_college)
recode educ_mom (6 = 1 "College") (0 1 2 3 4 5 7 8 9= 0) (else=.), gen(educ_mom_college)
recode educ_mom (7 8 = 1 "Post Grad") (0 1 2 3 4 5 6 9= 0) (else=.), gen(educ_mom_postBA)
recode educ_mom (9 = 1 "Missing") (0 1 2 3 4 5 6 7 8= 0) (else=.), gen(educ_mom_missing)
recode educ_mom (0 1 2 = 1 "Less HS")(3=2 "HS only")(4 5=3 "Some College")(6=4 "College")(7 8 =5 "Post Grad")(9=9 "Missing"), gen(ed5cat_mom)
recode educ_mom (0 1 2 3 = 1 "HS or less")(4 5=2 "Some College")(6=3 "College")(7 8 =4 "Post Grad")(9=9 "Missing"), gen(ed4cat_mom)

recode educ_dad (0 1 2 = 1 "Less HS") (3 4 5 6 7 8 9 = 0) (else=.), gen(educ_dad_no_hs)
recode educ_dad (3 = 1 "HS only") (0 1 2 4 5 6 7 8 9= 0) (else=.), gen(educ_dad_hs)
recode educ_dad (4 5 = 1 "Some College") (0 1 2 3 6 7 8 9= 0) (else=.), gen(educ_dad_some_college)
recode educ_dad (6 = 1 "College") (0 1 2 3 4 5 7 8 9= 0) (else=.), gen(educ_dad_college)
recode educ_dad (7 8 = 1 "Post Grad") (0 1 2 3 4 5 6 9= 0) (else=.), gen(educ_dad_postBA)
recode educ_dad (9 = 1 "Missing") (0 1 2 3 4 5 6 7 8= 0) (else=.), gen(educ_dad_missing)
recode educ_dad (0 1 2 = 1 "Less HS")(3=2 "HS only")(4 5=3 "Some College")(6=4 "College")(7 8 =5 "Post Grad")(9=9 "Missing"), gen(ed5cat_dad)
recode educ_dad (0 1 2 3 = 1 "HS or less")(4 5=2 "Some College")(6=3 "College")(7 8 =4 "Post Grad")(9=9 "Missing"), gen(ed4cat_dad)

//setting education to the voter
foreach v in _no_hs _hs _some_college _college _postBA _missing {
gen educ`v'=educ_mom`v' if newmom==1
replace educ`v'=educ_dad`v' if newdad==1
}

//PARTY 
gen DEM=0
gen GOP=0
replace DEM = 1 if partycode=="DEM"
replace GOP= 1 if partycode=="REP"
gen pid3cata = 0
replace pid3cata = -1 if DEM==1
replace pid3cata = 1 if GOP==1
lab def pid3cata -1 "DEM" 0 "Other/None" 1 "GOP"
lab val pid3cata pid3cata


//compare everyone to those who had babies in last week of December of that year
xi: reg turnout_g2012r priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2008 tooyoung08 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode 
est store parents

coefplot parents, keep(priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7)  title("Parents: 2012 Births") name("coefparents_2012", replace) scale(.75) ysize(10) xsize(5) xline(0)
graph export "Appendix_FigureA15a.tif", replace height(1200) width(600)

xi: reg turnout_g2012r priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6 postweek7 postweek7 turnout_g2008 tooyoung08 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if newmom==1
est store Moms

xi: reg turnout_g2012r priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2008 tooyoung08 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if newdad==1
est store Dads

coefplot Moms Dads, keep(priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7)  title(" Moms and Dads: 2012 Births") name("coefMF_2012", replace) scale(.75) ysize(10) xsize(5) xline(0)
graph export "Appendix_FigureA16a.tif", replace height(1200) width(600)

suest Moms Dads
test [Moms_mean]electionday = [Dads_mean]electionday
test [Moms_mean]priorweek1 = [Dads_mean]priorweek1
test [Moms_mean]priorweek2 = [Dads_mean]priorweek2
test [Moms_mean]priorweek3 = [Dads_mean]priorweek3
test [Moms_mean]priorweek4 = [Dads_mean]priorweek4
test [Moms_mean]priorweek5 = [Dads_mean]priorweek5
test [Moms_mean]priorweek6 = [Dads_mean]priorweek6
test [Moms_mean]priorweek7 = [Dads_mean]priorweek7
test [Moms_mean]priorweek8 = [Dads_mean]priorweek8
test [Moms_mean]priorweek9 = [Dads_mean]priorweek9
test [Moms_mean]postweek1 = [Dads_mean]postweek1
*sig 

//BY EDUCATION OF MOTHER
//run this separately by education category
//combining lowest two groups, since there are very few women with <HS degree 
forvalues x = 1/4 {
xi: reg turnout_g2012r priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2008 tooyoung08  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & ed4cat_mom==`x'
est store MomEd_`x'
}

coefplot (MomEd_1, label("<=HS")) (MomEd_4, label(">BA")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1)  title("By Mom's Level of Education") name(MomEd_LO_HI_Ed, replace) xline(0)

//BY HIGHER EDUCATION LEVEL WITHIN-COUPLE
egen ed4cat_partnermax = rowmax(ed4cat_mom ed4cat_dad)
//about half of our sample appears to be pairs of people joined to the same baby
forvalues x = 1/4 {
xi: reg turnout_g2012r priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2008 tooyoung08  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & ed4cat_partnermax==`x'
est store CoupleEd_`x'
}

coefplot (CoupleEd_1, label("<=HS")) (CoupleEd_4, label(">BA")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1)  title("By Education, Couple's Maximum") name(CoupleEd_LO_HI_Ed, replace) xline(0)
graph combine MomEd_LO_HI_Ed CoupleEd_LO_HI_Ed

//habit buffer
forvalues x = 0/1 {
xi: reg turnout_g2012r priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2008 tooyoung08  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & turnout_g2008 ==`x' & tooyoung08~=1
est store voted2008_`x'
}
coefplot (voted2008_0, label("Did not Vote 2008")) (voted2008_1, label("Voted 2008")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1)  title("By Turnout in 2008") name(figure2012_habit, replace) xline(0)


//INSTITUTIONAL BUFFER
//In 2012, it's a 9 week window
recode elapsedweeks (-52/-9 2/8=0)(-8/1=1 "9 week window")(else=.), gen(window9)

//BY WHETHER VOTED BY MAIL OR NOT
gen vbm2012=.
replace vbm2012=2 if method12=="VBM"|method12=="ERLY"
replace vbm2012=1 if method12=="POLL"
replace vbm2012=0 if turnout_g2012r==0
lab def vbm2012 0 "abstained" 1"Poll" 2"VBM"
lab val vbm2012 vbm2012
 
//past VBM in county
//only one county that is strictly VBM and has a newborn: countycode==46
gen pctvbm2008 =.
replace pctvbm2008=48.33 if countycode==1
replace pctvbm2008=100 if countycode==2
replace pctvbm2008=51.84 if countycode==3
replace pctvbm2008=49.44 if countycode==4
replace pctvbm2008=58.53 if countycode==5
replace pctvbm2008=49.34 if countycode==6
replace pctvbm2008=47.58 if countycode==7
replace pctvbm2008=48.44 if countycode==8
replace pctvbm2008=54.72 if countycode==9
replace pctvbm2008=45.32 if countycode==10
replace pctvbm2008=36.79 if countycode==11
replace pctvbm2008=40.63 if countycode==12
replace pctvbm2008=32.25 if countycode==13
replace pctvbm2008=43.19 if countycode==14
replace pctvbm2008=41.2 if countycode==15
replace pctvbm2008=64.23 if countycode==16
replace pctvbm2008=53.26 if countycode==17
replace pctvbm2008=44.21 if countycode==18
replace pctvbm2008=24.06 if countycode==19
replace pctvbm2008=54 if countycode==20
replace pctvbm2008=58.7 if countycode==21
replace pctvbm2008=55.25 if countycode==22
replace pctvbm2008=22.2 if countycode==23
replace pctvbm2008=40.29 if countycode==24
replace pctvbm2008=31.83 if countycode==25
replace pctvbm2008=33.73 if countycode==26
replace pctvbm2008=58.8 if countycode==27
replace pctvbm2008=27.5 if countycode==28
replace pctvbm2008=69.51 if countycode==29
replace pctvbm2008=46.54 if countycode==30
replace pctvbm2008=55.58 if countycode==31
replace pctvbm2008=58.74 if countycode==32
replace pctvbm2008=41.53 if countycode==33
replace pctvbm2008=44.19 if countycode==34
replace pctvbm2008=43.3 if countycode==35
replace pctvbm2008=37.19 if countycode==36
replace pctvbm2008=46 if countycode==37
replace pctvbm2008=46.01 if countycode==38
replace pctvbm2008=47.95 if countycode==39
replace pctvbm2008=51.04 if countycode==40
replace pctvbm2008=48.09 if countycode==41
replace pctvbm2008=52.16 if countycode==42
replace pctvbm2008=57.29 if countycode==43
replace pctvbm2008=47.06 if countycode==44
replace pctvbm2008=51.78 if countycode==45
replace pctvbm2008=100 if countycode==46
replace pctvbm2008=61.33 if countycode==47
replace pctvbm2008=51.09 if countycode==48
replace pctvbm2008=59.43 if countycode==49
replace pctvbm2008=52.889 if countycode==50
replace pctvbm2008=68.32 if countycode==51
replace pctvbm2008=54.83 if countycode==52
replace pctvbm2008=36.62 if countycode==53
replace pctvbm2008=36.81 if countycode==54
replace pctvbm2008=51.59 if countycode==55
replace pctvbm2008=43.52 if countycode==56
replace pctvbm2008=47.06 if countycode==57
replace pctvbm2008=47.98 if countycode==58

replace pctvbm2008 = . if countycode==2|countycode==49
replace pctvbm2008= pctvbm2008/100
gen VBMcounty=0
replace VBMcounty=1 if countycode==2|countycode==49

foreach v of varlist priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7  {
gen vbm`v'=pctvbm2008*`v'
}

forvalues v=1/7 {
lab var vbmpostweek`v' "%VBM x `v' weeks post"
}

forvalues v=1/44 {
lab var vbmpriorweek`v' "%VBM x `v' weeks prior"
}

lab var vbmelectionday "%VBM x Election Day"

forvalues v=3/58 {
rename _Icountycod_`v' countycode`v'
}
/*no values in county code = 2*/

/*mothers only*/
reg turnout_g2012r vbmp* vbmelectionday pctvbm turnout_g2008 tooyoung08 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode3-countycode48 countycode50-countycode57 if VBMcounty==0 & newmom==1
est store vbmp

*Prior Week 
capture postutil clear
tempfile priorresults
tempname memhold 
postfile `memhold' effect se pct priorweek using priorresults, replace
forvalues w=1(1)44 {
forvalues z=.3(.2).9 {
est restore vbmp
lincom priorweek`w' + `z'*vbmpriorweek`w'
post `memhold' (r(estimate)) (r(se)) (`z') (`w')
}
}
postclose `memhold​'

tempfile ED
tempname memhold 
postfile `memhold' effect se pct using ED, replace
forvalues z=.3(.2).9 {
est restore vbmp
lincom electionday + `z'*vbmelectionday
post `memhold' (r(estimate)) (r(se)) (`z')
}
postclose `memhold​'


tempfile afterresults2
tempname memhold 
postfile `memhold' effect se pct afterweek using afterresults2, replace
forvalues w=1(1)7 {
forvalues z=.3(.2).9 {
est restore vbmp
lincom postweek`w' + `z'*vbmpostweek`w'
post `memhold' (r(estimate)) (r(se)) (`z') (`w')
}
}
postclose `memhold​'

preserve
use priorresults, clear
gen w = -priorweek 
append using ED 
replace w = 0 if priorweek==.
append using afterresults2 
replace w = afterweek if w==.
table w pct, c(mean effect) 
gen LB = effect-invttail( 97227 ,.05)*se
gen UB = effect +invttail( 97227,.05)*se

lab def w -7 "7 weeks prior" -6 "6 weeks prior" -5 "5 weeks prior" -4 "4 weeks prior" -3 "3 weeks prior" -2 "2 weeks prior" -1 "1 week prior" 0"Election Day" 1 "1 week post", modify
lab val w w 

drop if pct>.4 & pct<.8
eclplot effect LB UB w if w>-8 & w<2, horizontal name(bygraph, replace) supby(pct) yscale(range(-7(1)1)) xline(0) title("Marginal Effect of Temporal Proximity of Birth" "Conditional on % VBM, 2012 Births") ylabel(-7(1)1,valuelabel) ytitle("")  legend(order(2 - "" 4 - "")) legend(label(2 "30% VBM") label(4 "90% VBM")) xsize(4) ysize(6) scale(.75)

graph export "Appendix_FigureA17a.tif", replace height(600) width(400)
restore

//mnl set-up 
//removing county 46 which is strictly VBM
xi: mlogit vbm2012 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2008 tooyoung08  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & countycode~=46, base(0)
est store vbm2012

recode vbm2012 (0=2 "Abstain")(1=0 "Poll")(2=1 "VBM"), gen(PollvVBMvAbstain2012)
xi: mlogit PollvVBMvAbstain2012 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2008 tooyoung08  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & countycode~=46, base(0)
est store PollvVBMvAbstain2012

recode vbm2012 (0=1 "Abstain")(1=0 "Poll")(2=2 "VBM"), gen(PollvAbstainvVBM2012)
xi: mlogit PollvAbstainvVBM2012 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2008 tooyoung08  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & countycode~=46, base(0)
est store PollvAbstainvVBM2012

coefplot (PollvVBMvAbstain2012, label("VBM vs. Polling Place")) (PollvAbstainvVBM2012, label("Abstain vs. Polling Place")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1) title("MNL Coefficient Estimates") xline(0) name(PollvVBMvAbstain, replace)

//recode vbm2012 for easier graphing 
recode vbm2012 (0=0 "Abstain")(1=2 "Poll")(2=1 "VBM"), gen(newvbm2012)
xi: mlogit newvbm2012 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2008 tooyoung08  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & countycode~=46, base(0)
est store newvbm2012

predict phat_abstain if e(sample), outcome(0)
predict phat_vbm if e(sample), outcome(1)
predict phat_poll if e(sample), outcome(2)
sum phat*

egen meanphat_abstain=mean(phat_abstain), by(elapsedweeks)
egen meanphat_vbm=mean(phat_vbm), by(elapsedweeks)
egen meanphat_poll=mean(phat_poll), by(elapsedweeks)

//generate conditional probability when vbm off the table
gen meanphat_noVBM_allowed = (meanphat_poll)/(meanphat_poll+meanphat_abstain)
table elapsedweeks, c(mean meanphat_noVBM_allowed)
gen meanphat_withVBM = (meanphat_poll+meanphat_vbm)

twoway (scatter meanphat_withVBM elapsedweeks if elapsedweeks<11, msymbol(O)) ///
(scatter meanphat_noVBM_allowed elapsedweeks if elapsedweeks<11, msymbol(T)) , ///
xscale(r(-40 10)) xlabel(-40(10)10) ///
yscale(r(0 1)) ylabel(0(.2)1) ytitle("Pr(Turnout)") ///
name(noVBM_2012, replace) legend(lab(1 "Current" ) lab(2 "No VBM Allowed")) ///
title("Turnout in a non-VBM World, Moms, 2012 Births") 

graph combine PollvVBMvAbstain noVBM_2012, row(1) ysize(5) xsize(9)
graph export "Appendix_FigureA17b.tif", replace height(1200) width(600)

graph drop _all

**********2014 ANALYSIS**********
use "deidentified_2014.dta", clear
gen dategen2014 = date("11/04/14","MDY",2014)
gen dob_B_year = substr(dob_B, 1, 4)
gen dob_B_month = substr(dob_B, 5, 2)
gen dob_B_day = substr(dob_B, 7, 2)
egen dob_B_newformat = concat(dob_B_month dob_B_day dob_B_year)
gen baby_dob_DATE=date(dob_B_newformat, "MDY")
gen elapseddays = baby_dob_DATE-dategen2014
gen electionday = 0
replace electionday = 1 if elapseddays==0 
recode elapseddays (-364/-358 =-52) (-357/-351 =-51) (-350/-344 =-50) (-343/-337 =-49) (-336/-330 =-48) (-329/-323 =-47) (-322/-316 =-46) (-315/-309 =-45) (-308/-302 =-44) (-301/-295 =-43) (-294/-288 =-42) (-287/-281 =-41) (-280/-274 =-40) (-273/-267 =-39) (-266/-260 =-38) (-259/-253 =-37) (-252/-246 =-36) (-245/-239 =-35) (-238/-232 =-34) (-231/-225 =-33) (-224/-218 =-32) (-217/-211 =-31) (-210/-204 =-30) (-203/-197 =-29) (-196/-190 =-28) (-189/-183 =-27) (-182/-176 =-26) (-175/-169 =-25) (-168/-162 =-24) (-161/-155 =-23) (-154/-148 =-22) (-147/-141 =-21) (-140/-134 =-20) (-133/-127 =-19) (-126/-120 =-18) (-119/-113 =-17) (-112/-106 =-16) (-105/-99 =-15) (-98/-92 =-14) (-91/-85 =-13) (-84/-78 =-12) (-77/-71 =-11) (-70/-64 =-10) (-63/-57 =-9) (-56/-50 =-8) (-49/-43 =-7) (-42/-36 =-6) (-35/-29 =-5) (-28/-22 =-4) (-21/-15 =-3) (-14/-8 =-2) (-7/-1 =-1) (0=0) (1/7 =1) (8/14 =2) (15/21 =3) (22/28 =4) (29/35 =5) (36/42 =6) (43/49 =7) (50/56 =8) (57/63 =9) (64/70 =10) (71/77 =11) (78/84 =12) (85/91 =13) (92/98 =14) (99/105 =15) (106/112 =16) (113/119 =17) (120/126 =18) (127/133 =19) (134/140 =20) (141/147 =21) (148/154 =22) (155/161 =23) (162/168 =24) (169/175 =25) (176/182 =26) (183/189 =27) (190/196 =28) (197/203 =29) (204/210 =30) (211/217 =31) (218/224 =32) (225/231 =33) (232/238 =34) (239/245 =35) (246/252 =36) (253/259 =37) (260/266 =38) (267/273 =39) (274/280 =40) (281/287 =41) (288/294 =42) (295/301 =43) (302/308 =44) (309/315 =45) (316/322 =46) (323/329 =47) (330/336 =48) (337/343 =49) (344/350 =50) (351/357 =51) (358/364 =52)  (else=.), gen(elapsedweeks)
forvalues v=1/52 {
recode elapsedweeks (-`v'=1)(else=0), gen(priorweek`v')
}
forvalues v=1/52 {
recode elapsedweeks (`v'=1)(else=0), gen(postweek`v')
}
forvalues v =1/45 {
lab var priorweek`v' "`v' weeks prior"
}
forvalues v=1/8 {
lab var postweek`v' "`v' weeks post"
}
lab var electionday "Election Day"
lab var elapsedweeks "Weeks Before and After Election"
lab var elapseddays "Days Before and After Election"

*****
*PARENT VARIABLES 
*****
egen gavebirth2012= rownonmiss(dob_B), strok
egen newmom= rownonmiss(dob_mom), strok
replace newmom=0 if newdad==1
replace newdad=0 if newmom==1|newdad~=1

*generating a new parent variable
gen newparent = 0
replace newparent = 2 if newmom==1
replace newparent = 1 if newdad==1
lab def newparent 0"not" 1"new dad" 2"new mom"
lab val newparent newparent

//AGE VARIABLES
*creating age variables 
gen yearborn = dob_year
destring yearborn, force replace
*note that this is going to be age in 2012
gen age = 2012-yearborn
gen agesq = age^2

//TURNOUT VARIABLES
gen newdob=date(dob,"YMD")
*tagging people who turned out in the 2014 election
gen turnout_g2014=0
replace turnout_g2014=1 if electiondate14R=="2014-11-04"

*tagging people who turnout out in the 2012 election 
gen turnout_g2012=0
replace turnout_g2012=1 if electiondate12R=="2012-11-06"

*tagging people who turned out in the 2010 election
gen turnout_g2010=0
replace turnout_g2010=1 if electiondate10R=="2010-11-02"

disp date("1996-11-04", "YMD")
recode newdob (-99999/13457=0)(13458/25000=1)(else=.), gen(tooyoung14)

disp date("1994-11-06", "YMD")
recode newdob(-99999/12728=0)(12729/25000=1)(else=.), gen(tooyoung12)
replace tooyoung12 =1 if newdob>12728

disp date("1992-11-02", "YMD")
recode newdob(-99999/11994=0)(11995/25000=1)(else=.), gen(tooyoung10)

gen turnout_g2014r = turnout_g2014
replace turnout_g2014r = . if tooyoung14==1

gen turnout_g2012r = turnout_g2012
replace turnout_g2012r = . if tooyoung12==1

gen turnout_g2010r = turnout_g2010
replace turnout_g2010r = . if tooyoung10==1
//include tooyoung10 with turnout_g2010 as a covariate when we model turnout in 2014

//COVARIATES
//RACE & ETHNICITY 
recode hisp_mom (1=0)(2/8=1)(9=0)(else=.), gen(hisp_mom_recoded)
recode race_mom_multi (1=1 "White")(2=2 "Black")(3=5 "American Indian")(4 5=4 "Asian")(6 7 9= 9 "Other/unknown")(else=.), gen(race5cat_mom)
replace race5cat_mom = 3 if hisp_mom_recoded==1
lab def race5cat_mom 3 "Hispanic", modify
recode race5cat_mom (2=1)(1 3/9=0)(else=.), gen(Black_Mom)
recode race5cat_mom (3=1)(1 2/9=0)(else=.), gen(Hisp_Mom)
recode race5cat_mom (4=1)(1 2 3/9=0)(else=.), gen(Asian_Mom)
recode race5cat_mom (5 9=1)(1 2 3 4 =0)(else=.), gen(Other_Mom)

recode hisp_dad (1=0)(2/8=1)(9=0)(else=.), gen(hisp_dad_recoded)
recode race_dad_multi (1=1 "White")(2=2 "Black")(3=5 "American Indian")(4 5=4 "Asian")(6 7 9= 9 "Other/unknown")(else=.), gen(race5cat_dad)
replace race5cat_dad = 3 if hisp_dad_recoded==1
lab def race5cat_dad 3 "Hispanic", modify
recode race5cat_dad (2=1)(1 3/9=0)(else=.), gen(Black_dad)
recode race5cat_dad (3=1)(1 2/9=0)(else=.), gen(Hisp_dad)
recode race5cat_dad (4=1)(1 2 3/9=0)(else=.), gen(Asian_dad)
recode race5cat_dad (5 9=1)(1 2 3 4 =0)(else=.), gen(Other_dad)

//setting race to the voter 
gen race5cat = race5cat_mom if newmom==1
replace race5cat = race5cat_dad if newdad==1
recode race5cat (2=1)(1 3/9=0)(else=.), gen(Black)
recode race5cat (3=1)(1 2/9=0)(else=.), gen(Hisp)
recode race5cat (4=1)(1 2 3/9=0)(else=.), gen(Asian)
recode race5cat (5 9=1)(1 2 3 4 =0)(else=.), gen(Other)
lab val race5cat race5cat_dad

//EDUCATION
recode educ_mom (0 1 2 = 1 "Less HS") (3 4 5 6 7 8 9 = 0) (else=.), gen(educ_mom_no_hs)
recode educ_mom (3 = 1 "HS only") (0 1 2 4 5 6 7 8 9= 0) (else=.), gen(educ_mom_hs)
recode educ_mom (4 5 = 1 "Some College") (0 1 2 3 6 7 8 9= 0) (else=.), gen(educ_mom_some_college)
recode educ_mom (6 = 1 "College") (0 1 2 3 4 5 7 8 9= 0) (else=.), gen(educ_mom_college)
recode educ_mom (7 8 = 1 "Post Grad") (0 1 2 3 4 5 6 9= 0) (else=.), gen(educ_mom_postBA)
recode educ_mom (9 = 1 "Missing") (0 1 2 3 4 5 6 7 8= 0) (else=.), gen(educ_mom_missing)
recode educ_mom (0 1 2 = 1 "Less HS")(3=2 "HS only")(4 5=3 "Some College")(6=4 "College")(7 8 =5 "Post Grad")(9=9 "Missing"), gen(ed5cat_mom)
recode educ_mom (0 1 2 3 = 1 "HS or less")(4 5=2 "Some College")(6=3 "College")(7 8 =4 "Post Grad")(9=9 "Missing"), gen(ed4cat_mom)

recode educ_dad (0 1 2 = 1 "Less HS") (3 4 5 6 7 8 9 = 0) (else=.), gen(educ_dad_no_hs)
recode educ_dad (3 = 1 "HS only") (0 1 2 4 5 6 7 8 9= 0) (else=.), gen(educ_dad_hs)
recode educ_dad (4 5 = 1 "Some College") (0 1 2 3 6 7 8 9= 0) (else=.), gen(educ_dad_some_college)
recode educ_dad (6 = 1 "College") (0 1 2 3 4 5 7 8 9= 0) (else=.), gen(educ_dad_college)
recode educ_dad (7 8 = 1 "Post Grad") (0 1 2 3 4 5 6 9= 0) (else=.), gen(educ_dad_postBA)
recode educ_dad (9 = 1 "Missing") (0 1 2 3 4 5 6 7 8= 0) (else=.), gen(educ_dad_missing)
recode educ_dad (0 1 2 = 1 "Less HS")(3=2 "HS only")(4 5=3 "Some College")(6=4 "College")(7 8 =5 "Post Grad")(9=9 "Missing"), gen(ed5cat_dad)
recode educ_dad (0 1 2 3 = 1 "HS or less")(4 5=2 "Some College")(6=3 "College")(7 8 =4 "Post Grad")(9=9 "Missing"), gen(ed4cat_dad)

//setting education to the voter
foreach v in _no_hs _hs _some_college _college _postBA _missing {
gen educ`v'=educ_mom`v' if newmom==1
replace educ`v'=educ_dad`v' if newdad==1
}

//PARTY 
gen DEM=0
gen GOP=0
replace DEM = 1 if partycode=="DEM"
replace GOP= 1 if partycode=="REP"
//set no party or other party to baseline
gen pid3cata = 0
replace pid3cata = -1 if DEM==1
replace pid3cata = 1 if GOP==1
lab def pid3cata -1 "DEM" 0 "Other/None" 1 "GOP"
lab val pid3cata pid3cata

//weekly data for Model 1
xi: reg turnout_g2014r priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2010 tooyoung10 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode 
est store parents

coefplot parents, keep(priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7  )  title("Parents: 2014 Births") name("coefparents_2014", replace) scale(.75) ysize(10) xsize(5) xline(0)
graph export "Appendix_FigureA15b.tif", replace height(1200) width(600)

xi: reg turnout_g2014r priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2010 tooyoung10 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if newmom==1
est store Moms

xi: reg turnout_g2014r priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2010 tooyoung10 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP i.countycode if newdad==1
est store Dads

coefplot Moms Dads, keep(priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 )  title(" Moms and Dads: 2014 Births") name("coefMF_2014", replace) scale(.75) ysize(10) xsize(5) xline(0)
graph export "Appendix_FigureA16b.tif", replace height(1200) width(600)

suest Moms Dads
test [Moms_mean]electionday = [Dads_mean]electionday
test [Moms_mean]priorweek1 = [Dads_mean]priorweek1
test [Moms_mean]priorweek2 = [Dads_mean]priorweek2
test [Moms_mean]priorweek3 = [Dads_mean]priorweek3
test [Moms_mean]priorweek4 = [Dads_mean]priorweek4
test [Moms_mean]priorweek5 = [Dads_mean]priorweek5
test [Moms_mean]priorweek6 = [Dads_mean]priorweek6
test [Moms_mean]priorweek7 = [Dads_mean]priorweek7
test [Moms_mean]priorweek8 = [Dads_mean]priorweek8
test [Moms_mean]priorweek9 = [Dads_mean]priorweek9
test [Moms_mean]postweek1 = [Dads_mean]postweek1

//BY EDUCATION OF MOTHER
//run this separately by education category
//combining lowest two groups, since there are very few women with <HS degree 
forvalues x = 1/4 {
xi: reg turnout_g2014r priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2010 tooyoung10  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & ed4cat_mom==`x'
est store MomEd_`x'
}

coefplot (MomEd_1, label("<=HS")) (MomEd_4, label(">BA")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1)  title("By Mom's Level of Education, 2014 Births") name(MomEd_LO_HI_Ed, replace) xline(0)

//BY HIGHER EDUCATION LEVEL WITHIN-COUPLE
egen ed4cat_partnermax = rowmax(ed4cat_mom ed4cat_dad)
//about half of our sample appears to be pairs of people joined to the same baby
forvalues x = 1/4 {
xi: reg turnout_g2014r turnout_g2010r tooyoung10 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6 postweek7 age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & ed4cat_partnermax==`x'
est store CoupleEd_`x'
}

coefplot (CoupleEd_1, label("<=HS")) (CoupleEd_4, label(">BA")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1)  title("By Education, Couple's Maximum") name(CoupleEd_LO_HI_Ed, replace) xline(0)
graph combine MomEd_LO_HI_Ed CoupleEd_LO_HI_Ed

//habit buffer
forvalues x = 0/1 {
xi: reg turnout_g2014r priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2010 tooyoung10  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & turnout_g2010 ==`x' & tooyoung10~=1
est store voted2010_`x'
}
coefplot (voted2010_0, label("Did not Vote 2010")) (voted2010_1, label("Voted 2010")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1)  title("By Turnout in 2010") name(figure2014_habit, replace) xline(0)

suest voted2010_0 voted2010_1
test [voted2010_1_mean]electionday = [voted2010_0_mean]electionday
test [voted2010_1_mean]priorweek1 = [voted2010_0_mean]priorweek1
test [voted2010_1_mean]priorweek2 = [voted2010_0_mean]priorweek2
test [voted2010_1_mean]priorweek3 = [voted2010_0_mean]priorweek3
test [voted2010_1_mean]priorweek4 = [voted2010_0_mean]priorweek4
test [voted2010_1_mean]priorweek5 = [voted2010_0_mean]priorweek5


//INSTITUTIONAL BUFFER
//BY WHETHER VOTED BY MAIL OR NOT
gen vbm2014=.
replace vbm2014=2 if method14=="VBM"|method14=="ERLY"
replace vbm2014=1 if method14=="POLL"
replace vbm2014=0 if turnout_g2014r==0
lab def vbm2014 0 "abstained" 1"Poll" 2"VBM"
lab val vbm2014 vbm2014
 
//past VBM in county 
gen pctvbm2010 =.
replace pctvbm2010=54.11 if countycode==1
replace pctvbm2010=100 if countycode==2
replace pctvbm2010=58.56 if countycode==3
replace pctvbm2010=57.01 if countycode==4
replace pctvbm2010=62.85 if countycode==5
replace pctvbm2010=43.52 if countycode==6
replace pctvbm2010=53.16 if countycode==7
replace pctvbm2010=54.88 if countycode==8
replace pctvbm2010=70.53 if countycode==9
replace pctvbm2010=52.87 if countycode==10
replace pctvbm2010=40.71 if countycode==11
replace pctvbm2010=47.86 if countycode==12
replace pctvbm2010=36.59 if countycode==13
replace pctvbm2010=47.08 if countycode==14
replace pctvbm2010=47.92 if countycode==15
replace pctvbm2010=69.6 if countycode==16
replace pctvbm2010=57.54 if countycode==17
replace pctvbm2010=36.87 if countycode==18
replace pctvbm2010=28.55 if countycode==19
replace pctvbm2010=59.24 if countycode==20
replace pctvbm2010=60.36 if countycode==21
replace pctvbm2010=60.46 if countycode==22
replace pctvbm2010=79.4 if countycode==23
replace pctvbm2010=46.61 if countycode==24
replace pctvbm2010=35.64 if countycode==25
replace pctvbm2010=36.62 if countycode==26
replace pctvbm2010=65.18 if countycode==27
replace pctvbm2010=30.34 if countycode==28
replace pctvbm2010=73.85 if countycode==29
replace pctvbm2010=51.9 if countycode==30
replace pctvbm2010=59.01 if countycode==31
replace pctvbm2010=69 if countycode==32
replace pctvbm2010=48.12 if countycode==33
replace pctvbm2010=52.75 if countycode==34
replace pctvbm2010=46.63 if countycode==35
replace pctvbm2010=44 if countycode==36
replace pctvbm2010=55.07 if countycode==37
replace pctvbm2010=50.35 if countycode==38
replace pctvbm2010=59.77 if countycode==39
replace pctvbm2010=58.61 if countycode==40
replace pctvbm2010=52.08 if countycode==41
replace pctvbm2010=57.58 if countycode==42
replace pctvbm2010=68.48 if countycode==43
replace pctvbm2010=51.41 if countycode==44
replace pctvbm2010=57.13 if countycode==45
replace pctvbm2010=100 if countycode==46
replace pctvbm2010=65.24 if countycode==47
replace pctvbm2010=56.25 if countycode==48
replace pctvbm2010=63.44 if countycode==49
replace pctvbm2010=64.13 if countycode==50
replace pctvbm2010=68.19 if countycode==51
replace pctvbm2010=59.45 if countycode==52
replace pctvbm2010=65.74 if countycode==53
replace pctvbm2010=39.89 if countycode==54
replace pctvbm2010=55.86 if countycode==55
replace pctvbm2010=49.01 if countycode==56
replace pctvbm2010=49.42 if countycode==57
replace pctvbm2010=56.78 if countycode==58

replace pctvbm2010 = . if countycode==2|countycode==49
replace pctvbm2010= pctvbm2010/100

gen VBMcounty=0
replace VBMcounty=1 if countycode==2|countycode==49

foreach v of varlist priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7  {
gen vbm`v'=pctvbm2010*`v'
}

forvalues v=1/7 {
lab var vbmpostweek`v' "%VBM x `v' weeks post"
}

forvalues v=1/44 {
lab var vbmpriorweek`v' "%VBM x `v' weeks prior"
}

lab var vbmelectionday "%VBM x Election Day"

forvalues v=2/58 {
rename _Icountycod_`v' countycode`v'
}

/*mothers only*/
reg turnout_g2014r vbmp* vbmelectionday pctvbm turnout_g2010 tooyoung10 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 age agesq Black Hisp Asian Other educ_hs educ_some_college educ_college educ_postBA educ_missing DEM GOP countycode3-countycode48 countycode50-countycode57 if VBMcounty==0 & newmom==1
est store vbmp

//no significant interactions 
capture postutil clear
tempfile priorresults
tempname memhold 
postfile `memhold' effect se pct priorweek using priorresults, replace
forvalues w=1(1)44 {
forvalues z=.3(.2).9 {
est restore vbmp
lincom priorweek`w' + `z'*vbmpriorweek`w'
post `memhold' (r(estimate)) (r(se)) (`z') (`w')
}
}
postclose `memhold​'

tempfile ED
tempname memhold 
postfile `memhold' effect se pct using ED, replace
forvalues z=.3(.2).9 {
est restore vbmp
lincom electionday + `z'*vbmelectionday
post `memhold' (r(estimate)) (r(se)) (`z')
}
postclose `memhold​'


tempfile afterresults2
tempname memhold 
postfile `memhold' effect se pct afterweek using afterresults2, replace
forvalues w=1(1)7 {
forvalues z=.3(.2).9 {
est restore vbmp
lincom postweek`w' + `z'*vbmpostweek`w'
post `memhold' (r(estimate)) (r(se)) (`z') (`w')
}
}
postclose `memhold​'

preserve
use priorresults, clear
gen w = -priorweek 
append using ED 
replace w = 0 if priorweek==.
append using afterresults2 
replace w = afterweek if w==.
table w pct, c(mean effect) 
gen LB = effect-invttail( 118811 ,.05)*se
gen UB = effect +invttail( 118811,.05)*se

lab def w -7 "7 weeks prior" -6 "6 weeks prior" -5 "5 weeks prior" -4 "4 weeks prior" -3 "3 weeks prior" -2 "2 weeks prior" -1 "1 week prior" 0"Election Day" 1 "1 week post", modify
lab val w w 
drop if pct>.4 & pct<.8
eclplot effect LB UB w if w>-8 & w<2, horizontal name(bygraph, replace) supby(pct) yscale(range(-7(1)1)) xline(0) title("Marginal Effect of Temporal Proximity of Birth" "Conditional on % VBM, 2014 Births") ylabel(-7(1)1,valuelabel) ytitle("")  legend(order(2 - "" 4 - "")) legend(label(2 "30% VBM") label(4 "90% VBM")) xsize(4) ysize(6) scale(.75)

graph export "Appendix_FigureA18a.tif", replace height(600) width(400)
restore

 //MNL Model
xi: mlogit vbm2014 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2010 tooyoung10  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & VBMcounty==0, base(0)
est store vbm2014

//recoding for final graph
recode vbm2014 (0=2 "Abstain")(1=0 "Poll")(2=1 "VBM"), gen(PollvVBMvAbstain2014)
xi: mlogit PollvVBMvAbstain2014 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2010 tooyoung10  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & VBMcounty==0, base(0)
est store PollvVBMvAbstain2014

recode vbm2014 (0=1 "Abstain")(1=0 "Poll")(2=2 "VBM"), gen(PollvAbstainvVBM2014)
xi: mlogit PollvAbstainvVBM2014 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2010 tooyoung10  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & VBMcounty==0, base(0)
est store PollvAbstainvVBM2014

coefplot (PollvVBMvAbstain2014, label("VBM vs. Polling Place")) (PollvAbstainvVBM2014, label("Abstain vs. Polling Place")), keep(priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1) title("MNL Coefficient Estimates") xline(0) name(PollvVBMvAbstain, replace)

//recode vbm2014 for easier graphing 
recode vbm2014 (0=0 "Abstain")(1=2 "Poll")(2=1 "VBM"), gen(newvbm2014)
xi: mlogit newvbm2014 priorweek44 priorweek43 priorweek42 priorweek41 priorweek40 priorweek39 priorweek38 priorweek37 priorweek36 priorweek35 priorweek34 priorweek33 priorweek32 priorweek31 priorweek30 priorweek29 priorweek28 priorweek27 priorweek26 priorweek25 priorweek24 priorweek23 priorweek22 priorweek21 priorweek20 priorweek19 priorweek18 priorweek17 priorweek16 priorweek15 priorweek14 priorweek13 priorweek12 priorweek11 priorweek10 priorweek9 priorweek8 priorweek7 priorweek6 priorweek5 priorweek4 priorweek3 priorweek2 priorweek1 electionday  postweek1  postweek2  postweek3  postweek4  postweek5  postweek6  postweek7 turnout_g2010 tooyoung10  age agesq Black Hisp Asian Other DEM GOP i.countycode if newmom==1 & VBMcounty==0, base(0)
est store newvbm2014

predict phat_abstain if e(sample), outcome(0)
predict phat_vbm if e(sample), outcome(1)
predict phat_poll if e(sample), outcome(2)
egen meanphat_abstain=mean(phat_abstain), by(elapsedweeks)
egen meanphat_vbm=mean(phat_vbm), by(elapsedweeks)
egen meanphat_poll=mean(phat_poll), by(elapsedweeks)

//consider a simulated world where the decision is abstain versus polling place
//take the first set of mlogit coeffs, comparing poll to abstained
//project those values onto in-sample values

table elapsedweeks, c(mean meanphat_abstain mean meanphat_poll mean meanphat_vbm)

//generate conditional probability when vbm off the table
gen meanphat_noVBM_allowed = (meanphat_poll)/(meanphat_poll+meanphat_abstain)
table elapsedweeks, c(mean meanphat_noVBM_allowed)
gen meanphat_withVBM = (meanphat_poll+meanphat_vbm)

twoway (scatter meanphat_withVBM elapsedweeks if elapsedweeks<11, msymbol(O)) ///
(scatter meanphat_noVBM_allowed elapsedweeks if elapsedweeks<11, msymbol(T)) , ///
xscale(r(-40 10)) xlabel(-40(10)10) ///
yscale(r(0 1)) ylabel(0(.2)1) ytitle("Pr(Turnout)") ///
name(noVBM_2014, replace) legend(lab(1 "Current" ) lab(2 "No VBM Allowed")) ///
title("Turnout in a non-VBM World, Moms, 2014 Births") 
graph combine PollvVBMvAbstain noVBM_2014, row(1) ysize(5) xsize(9)
graph export "Appendix_FigureA18b.tif", replace height(600) width(400)


log close